# Confused about dispatch on type

**URL:** <https://discourse.julialang.org/t/confused-about-dispatch-on-type/5406>\
**Category:** New to Julia\
**Created:** [August 16, 2017, 8:02am UTC](https://discourse.julialang.org/t/confused-about-dispatch-on-type/5406 "2017-08-16T08:02:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [August 16, 2017, 8:02am UTC](https://discourse.julialang.org/t/confused-about-dispatch-on-type/5406/1 "2017-08-16T08:02:55Z")

</div>

Hi,

I am playing with MLDataPattern and I am confused with use of ObservationDimension. The problem is that I cannot use it inside the definition of a type in function. To be clear, I have replicated that in this toy example:

> immutable Constant{DIM} end  
> Constant(dim::Int) = Constant{dim}()  
> function x(c::A) where {A::Constant{1}}  
> println(“1”)  
> end

The compiler returns an error

> ERROR: syntax: invalid variable expression in “where”

Even though

> isa(Constant(1),Constant{1})  
> this works properly.

What am I doing wrong?

Thanks for help.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [August 16, 2017, 8:26am UTC](https://discourse.julialang.org/t/confused-about-dispatch-on-type/5406/2 "2017-08-16T08:26:43Z")

</div>

Just use

```julia
function x(c::Constant{1})

```

as there’s no need for the `where` notation here. If you did wanna use that then the correct incantation is

```julia
function x(c::T) where T<:Constant{1}

```

Notice `<:` (which defines a subtyping relation) instead of `::` (which defines an `isa` relation). The former doesn’t really make sense for concrete types though.

---

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [August 16, 2017, 12:08pm UTC](https://discourse.julialang.org/t/confused-about-dispatch-on-type/5406/3 "2017-08-16T12:08:40Z")

</div>

Thank you very much. It works!!
