You need to declare the type parameter on Foo:

type Foo1{B<:Bar} <: Foo{B}
    bar::B
end

On Sun, Aug 10, 2014 at 3:37 PM, thom lake <[email protected]> wrote:
> Not sure if the title and/or nomenclature are correct, but I need to write a
> function that dispatches on the specific type "inner" type while ignoring
> the "outer" type. An example is probably worth a thousand words: This is the
> closest thing I can get that compiles but errors at runtime.
>
> abstract Bar
> abstract Foo{B<:Bar}
>
> type Foo1{B<:Bar} <: Foo
>     bar::B
> end
>
> type Foo2{B<:Bar} <: Foo
>     bar::B
> end
>
> type Bar1 <: Bar
>     x::Int
> end
> Bar1() = Bar1(1)
>
> type Bar2 <: Bar
>     x::Int
> end
> Bar2() = Bar2(2)
>
> bar_type_str(foo::Foo{Bar1}) = "Bar1"
> bar_type_str(foo::Foo{Bar2}) = "Bar2"
>
> foo = Foo1(Bar1())
> println(bar_type_str(foo))
>
> The exact error I get is
>
> ERROR: `bar_type_str` has no method matching bar_type_str(::Foo1{Bar1})
>
> Is there a way I can achieve what I'm looking for, or perhaps a better way
> of accomplishing what I want to do. The only thing I can think of is to
> split the Foo and Bar type apart, which will be somewhat inelegant in my
> specific application.

Reply via email to