Thanks!  I actually do have T in different locations so that was really 
helpful.



> On 4 Mar 2015, at 2:06 pm, Jameson Nash <[email protected]> wrote:
> 
> It'll work (here), but it will be wrong in general.
> 
> you actually want:
> 
> Base.eltype{T<:Foo}(::Type{T}) = eltype(super(T))
> 
> (i believe that this definition is already built in to 0.4, so in 0.4, it 
> will "just work" given your first method definition below. but in 0.3, you 
> may need to write this definition yourself)
> 
> In particular, Keno's code will fail given other possible type definitions, 
> such as
> 
> type Foo2 <: Foo{Int}; end
> 
> or 
> 
> type Foo3{A, T} <: Foo{T}; end
> 
> 
> On Tue, Mar 3, 2015 at 10:03 PM Sheehan Olver <[email protected] 
> <mailto:[email protected]>> wrote:
> 
>       Beautiful!!   Now to rewrite the 100 for loops I made over every 
> possible choice of T :)
> 
> 
> 
> 
>> On 4 Mar 2015, at 2:01 pm, Keno Fischer <[email protected] 
>> <mailto:[email protected]>> wrote:
>> 
>> Base.eltype{T<:Foo}(::Type{T})=T.parameters[1]
>> 
>> should work
>> 
>> On Tue, Mar 3, 2015 at 9:58 PM, Sheehan Olver <[email protected] 
>> <mailto:[email protected]>> wrote:
>> Suppose I have
>> 
>> abstract Foo{T}
>> immutable Foo1{T} <:Foo{T} end
>> immutable Foo2{T} <:Foo{T} end
>> 
>> 
>> 
>> How can I write a function that returns T given the type?  E.g.: I want to do
>> 
>> Base.eltype(::Type{Foo{T}})=T
>> 
>> 
>> But this won't work for eltype(Foo1{T})
>> 
>> 
>> 
>> 
> 

Reply via email to