Supplying the type parameter explicitly invokes the inner constructor. For
non-parametric types, there's a single generic function that both inner and
outer constructor methods belong to – so the only distinction between the
inner and outer ones is where they occur (and thus whether they have access
to new or not). For parametric types, however, inner constructor methods
are added to the Foo{T} object whereas outer constructor methods are added
to the Foo object. It's a but confusing, I know.

On Tue, Feb 10, 2015 at 12:38 PM, Michael Francis <[email protected]>
wrote:

> But why is the outer constructor not called in this case ?
>
> On Tuesday, February 10, 2015 at 12:35:44 PM UTC-5, Stefan Karpinski wrote:
>>
>> The inner constructor only has a zero-argument method:
>>
>> julia> Foo{Int}()
>> Foo{Int64}(0)
>>
>>
>> If you add a second inner constructor method, then you can call it.
>>
>> On Tue, Feb 10, 2015 at 12:15 PM, Michael Francis <[email protected]>
>> wrote:
>>
>>> A slightly simplified example, If I pin the type parameter I am unable
>>> to create the new object. I'm sure I'm missing something obvious here but
>>> given that Int 1 defaults to Int64 on my system I would expect both lines
>>> to work ?
>>>
>>> abstract Bar
>>> type Foo{T} <: Bar
>>>   t::T
>>>   Foo() = new( zero( T ) )
>>> end
>>> Foo{T}( d::T) = ( this = Foo{T}() ; this.t = d; this )
>>>
>>> Foo{Int}( 1)    # Foo{Int64} has no method matching Foo{Int64}(::Int64)
>>> Foo( 1)         # Works
>>>
>>
>>

Reply via email to