starting with your `*T*` parameterized type
   type Foo{*T*} 
    x::Vector{*T*} 
  end
When you create a new element of type Foo by giving the concrete type a 
vector of some sort, say [1,2,3],
   newFoo = Foo( [1,2,3] )
you do not write out the *T*, nor do you explicitly give it its appropriate 
value (the type of the elements in the vector).
Julia sees that you are calling Foo with [1,2,3] and Foo knows that it is 
parameterized by the type of the elements in the vector.
Julia, seeing that you are calling Foo with [1,2,3], discerns that, for 
this invocation of Foo, *T is Int64 *(which is eltype([1,2,3]) on 64bit 
machines)
   newFoo = Foo( [1,2,3] ) # Foo{Int64}( [1,2,3] )
And we can see this directly by defining
   Base.eltype{T}(x::Foo{T}) = T
which tells eltype() when given a Foo thing to report the type that has 
become the value for the parameter *T* (made so when Foo was called to make 
that Foo thing).
   eltype(newFoo) == Int64

   you know what  this         this  is and does
                                     ----------                ----------
call{T}( ::Type{ Foo{*T*} } ) = Foo{*T*}(  T[]  )
call{*T*}( ::Type{ Foo{*T*} } ) = Foo{*T*}( (T)[] )      # the same as the 
line above, here (T)[] makes explicit that [] gets {T)'d
     ^               ^            ^    *
 that pulls out     this         this    it tells Julia there is a 
parameter designated T that is to occur within the function/call signature
                                       *
     v                                 v          we can re-put in the T we 
pulled out, and when we do, it re-Ts 
call{*T*}( ::Type{ Foo{*T*} } ) = Foo{*T*}( (*T*)[] ) 

which gives you
julia> Foo{ Float64 }() # () calls that above
Foo{Float64}( (Float64)[] ) # or
Foo{Float64}( Float64[] )


On Tuesday, April 5, 2016 at 7:32:51 AM UTC-4, Anonymous wrote:
>
> hey alright! that works, thanks.  Is there an explanation of how this 
> works in the tutorial?
>
> On Tuesday, April 5, 2016 at 4:17:28 AM UTC-7, Kristoffer Carlsson wrote:
>>
>> call{T}(::Type{Foo{T}}) = Foo{T}(T[])
>>
>> julia> Foo{Float64}()
>> Foo{Float64}(Float64[])
>>
>>
>>
>> On Tuesday, April 5, 2016 at 1:12:00 PM UTC+2, Anonymous wrote:
>>>
>>> I couldn't really figure out a good way to describe it my title, but 
>>> what I'm trying to do is this:
>>>
>>> type Foo{T}
>>> x::Vector{T}
>>> end
>>>
>>> Foo{T}() = Foo{T}(T[])
>>>
>>> but I get the warning msg: Warning: static parameter T does not occur in 
>>> signature for call at none:1.  The method will not be callable.
>>>
>>> How can I do this?
>>>
>>>

Reply via email to