# Interesting problem with where parameters

**URL:** https://discourse.julialang.org/t/interesting-problem-with-where-parameters/18824
**Category:** General Usage
**Created:** [December 19, 2018, 11:00am UTC](https://discourse.julialang.org/t/interesting-problem-with-where-parameters/18824 "2018-12-19T11:00:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)
#### Post date: [December 19, 2018, 11:00am UTC](https://discourse.julialang.org/t/interesting-problem-with-where-parameters/18824/1 "2018-12-19T11:00:48Z")

</div>

I have the following code:

```nohighlight
    abstract type TypedFun end

    abstract type ReturnFun{R} <: TypedFun end

    abstract type NoArgFun{R} <: ReturnFun{R} end

    abstract type FullFun{Tuple,R} <: ReturnFun{R} end

    #single argument function
    struct SAFun{T,R} <: FullFun{Tuple{T},R}
        fn::Function
    end

    (⇒)(::Type{T}, ::Type{R}) where {T,R} = SAFun{T, R}
    (⇒)(::Nothing, ::Type{R}) where {R} = NoArgFun{R}

   struct MM{T}
     x::T
   end

   f(fun::(Any ⇒ MM{T})) where T = fun(3) 

```

the function f definition gives the following error

ERROR: UndefVarError: R not defined

However this doesn’t give the same error:

```nohighlight
f(fun::(Any ⇒ MM)) = fun(3)

```

Why is this happening…

Thanks, and how can I fix it?

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [December 19, 2018, 11:04am UTC](https://discourse.julialang.org/t/interesting-problem-with-where-parameters/18824/2 "2018-12-19T11:04:11Z")

</div>

Please provide a **self-contained** example. We don’t know what `SAFun` is and you are not providing a stack trace.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [December 19, 2018, 11:13am UTC](https://discourse.julialang.org/t/interesting-problem-with-where-parameters/18824/3 "2018-12-19T11:13:39Z")

</div>

This works `f(fun::(Any ⇒ MM{T} where T)) = fun(3)`. Note though that the `Any ⇒ MM{T} where T` part is evaluated at function definition and not later. Thus having the `where` outside does not make sense.

---

<div class="post-metadata">

### Author: ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)
#### Post date: [December 19, 2018, 7:51pm UTC](https://discourse.julialang.org/t/interesting-problem-with-where-parameters/18824/4 "2018-12-19T19:51:57Z")

</div>

what if the same T is used in other parameters of the function such as

f(x::T, fun::(Any ⇒ MM{T})) where T = fun(x)

how do we fix this?
