Whoops... yes, I should have read through more carefully. Yes, if `T` is abstract, you will lose performance. Sorry for the misdirection.
Kevin On Thu, Feb 4, 2016 at 11:56 AM, Josh Langsfeld <[email protected]> wrote: > I may be mistaken, but I think setting the type parameter to be abstract > is indeed the same as setting the field itself to be abstract. This snippet > is my evidence: > > julia> abstract ABC > > julia> immutable A <: ABC > a::Float32 > end > > julia> type B{T<:ABC} > a::T > end > > julia> bA, bABC = B{A}(A(1)), B{ABC}(A(2)) > (B{A}(A(1.0f0)),B{ABC}(A(2.0f0))) > > julia> sizeof(bA), sizeof(bABC) > (4,8) > > Even though both 'B' objects contain an 'A' immutable, bABC keeps it as a > pointer (size 8) whereas bA can directly unpack it into the definition. > > > On Thursday, February 4, 2016 at 1:59:17 PM UTC-5, Christopher Alexander > wrote: >> >> Oh cool! I was worried, since my call method was passing in the abstract >> type if none was specified (ie I wasn't setting a value for the param "a"), >> that it would just be the same as if I hadn't used a parametric type at all >> and just set the type of "a" to the abstract type. >> >> Thanks! >> >> Chris >> >> On Thursday, February 4, 2016 at 11:50:07 AM UTC-5, Kevin Squire wrote: >>> >>> No, `a` is the (concrete) type `T`, which is a subtype of `ABC` (and a >>> new type `B{T}` is created for each `T`). So you shouldn't lose >>> performance because of this. >>> >>> Cheers, >>> Kevin >>> >>> On Thu, Feb 4, 2016 at 8:10 AM, Christopher Alexander <[email protected] >>> > wrote: >>> >>>> Let's say I have the following types: >>>> >>>> abstract ABC >>>> >>>> type A <: ABC >>>> a::Float64 >>>> end >>>> >>>> type B{T <: ABC} >>>> a::T >>>> end >>>> >>>> In some cases, I need for type "B" to be incompletely initialized so >>>> that I can define its parameter "a" later. I've found out that you can do >>>> something like this: >>>> >>>> type B{T <: ABC} >>>> a::T >>>> >>>> call(::Type{B}) = new{ABC}() >>>> end >>>> >>>> which then allows this: >>>> >>>> julia> myB = B() >>>> B{ABC}(#undef) >>>> >>>> My question is, I'm assuming you lose any of the performance gain by >>>> using the parametric type in this case because you are still using the >>>> abstract type "ABC" for the parameter "a" (even if you define it later with >>>> a concrete "A"). Is there a better way to do this? >>>> >>>> Thanks! >>>> >>>> Chris >>>> >>> >>>
