Defining a constructor for partially parameterized type

If I have a parameterized type Foo{X,Y}, how can I define a constructor for Foo{X} that assigns a default value to Y?

For example, the following didn’t work:

julia> type Foo{X,Y}; end
julia> (::Foo{X}){X}() = Foo{X,true}()

julia> Foo{Int}()
ERROR: MethodError: no method matching Foo{Int64,Y}()
Closest candidates are:
  Foo{Int64,Y}{T}(::Any) at sysimg.jl:53

Oh, nevermind, I just realized that I need:

(::Type{Foo{X}}){X}() = Foo{X,true}()

(I was missing the Type)

The method (::Type{Foo{X}}){X}() is a constructor. What is (::Foo{X}){X}()?

http://docs.julialang.org/en/release-0.5/manual/methods/#function-like-objects

1 Like