# How to declare parametric with return type of a function?

**URL:** <https://discourse.julialang.org/t/how-to-declare-parametric-with-return-type-of-a-function/40288>\
**Category:** General Usage\
**Created:** [May 27, 2020, 8:23pm UTC](https://discourse.julialang.org/t/how-to-declare-parametric-with-return-type-of-a-function/40288 "2020-05-27T20:23:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ronneesley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronneesley/32/11072_2.png) [@Ronneesley](https://discourse.julialang.org/u/Ronneesley)\
**Post date:** [May 27, 2020, 8:23pm UTC](https://discourse.julialang.org/t/how-to-declare-parametric-with-return-type-of-a-function/40288/1 "2020-05-27T20:23:17Z")

</div>

I have a method and I want to declare it with **parametric** and with **return type**.  
What is the syntax?

```julia
f(a::T)::Bool where {T <: Number} = a == 1

```

The error message is:

```julia
ERROR: UndefVarError: T not defined
Stacktrace:
 [1] top-level scope at REPL[4]:1

```

I know that there is another way to resolve this problem, but it’s a simplified version of my real problem. It is: I have a method declared with a return type and now I want to put a parametric argument.

The real question is: there is a syntax to declare both parametric argument and return type?

Thanks.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [May 27, 2020, 8:31pm UTC](https://discourse.julialang.org/t/how-to-declare-parametric-with-return-type-of-a-function/40288/2 "2020-05-27T20:31:58Z")

</div>

It’s just a slightly annoying parsing issue. Your definition is getting parsed as `f(a::T)::(Bool where {T <: Number})`, which isn’t what you want. You can do:

```julia
julia> (f(a::T)::Bool) where {T <: Number} = a == 1
f (generic function with 1 method)

julia> f(1.0)
true

```

And by the way, you can see for yourself how the expression is parsed by quoting it, in case you’re ever curious:

```julia
julia> :(f(a::T)::Bool where {T <: Number} = a == 1)
:(f(a::T)::(Bool where T <: Number) = begin
          #= REPL[3]:1 =#
          a == 1
      end)

```

note how the `(Bool where T <: Number)` is grouped together.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [May 27, 2020, 8:32pm UTC](https://discourse.julialang.org/t/how-to-declare-parametric-with-return-type-of-a-function/40288/3 "2020-05-27T20:32:50Z")

</div>

Alternatively, you might find that the long-form function syntax is more readable here (and doesn’t have this parsing issue):

```julia
julia> function f(a::T)::Bool where {T <: Number}
         a == 1
       end
f (generic function with 1 method)

julia> f(1)
true

```

---

<div class="post-metadata">

**Author:** ![Ronneesley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronneesley/32/11072_2.png) [@Ronneesley](https://discourse.julialang.org/u/Ronneesley)\
**Post date:** [May 27, 2020, 8:45pm UTC](https://discourse.julialang.org/t/how-to-declare-parametric-with-return-type-of-a-function/40288/4 "2020-05-27T20:45:06Z")

</div>

It’s it. Thanks.
