# Generic type function

**URL:** <https://discourse.julialang.org/t/generic-type-function/15436>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [September 24, 2018, 8:34pm UTC](https://discourse.julialang.org/t/generic-type-function/15436 "2018-09-24T20:34:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hasanOryx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hasanoryx/32/5373_2.png) [@hasanOryx](https://discourse.julialang.org/u/hasanOryx)\
**Post date:** [September 24, 2018, 8:34pm UTC](https://discourse.julialang.org/t/generic-type-function/15436/1 "2018-09-24T20:34:48Z")

</div>

I’m trying to create a function that is having 2 input parameters of generic type `T` as below:

```julia
function mysum(x::T, y::T)
       x+y
end

```

but I got:

> ERROR: UndefVarError: T not defined

 ![Capture](https://global.discourse-cdn.com/julialang/original/3X/f/f/ff9acfec144cbd0206a258f222bc4795552cb892.png)

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 24, 2018, 8:36pm UTC](https://discourse.julialang.org/t/generic-type-function/15436/2 "2018-09-24T20:36:49Z")

</div>

You need

```julia
function mysum(x::T, y::T) where T
    x+y
end

```

See [Methods · The Julia Language](https://docs.julialang.org/en/v1/manual/methods/#Parametric-Methods-1).
