On Monday, January 6, 2014 3:14:06 PM UTC-5, Tim Holy wrote:
> There may be two separate issues here.
> - Without putting concrete types on x and y, it will never be fast. But
> let's
> suppose you planned to do that (as you did for the types in your gist),
> and
> were just being brief in your email.
>
yup.
> - There is no penalty for making B and C subtypes of A; myfunc(object::A)
> will
> be compiled twice, once for when object is a B and once when it is a C.
> Moreover, when Julia can infer types in functions that call myfunc, it
> will
> make that decision, too, at compile-time. So in favorable cases there is
> literally no run-time overhead for creating subtypes of an abstract type.
>
That's in the case where your code asserts the type, correct?
abstract A; end
type B<:A; x::Int; end
type C<:A; y::Int; end
I think the following might illustrate what I'm wondering.
Say arr::Array{A}, and odd elements have type B but even elements have C.
This is slow, right?
for i=1:2:length(arr) arr[i].x end
Will this be fast? Can Julia get away with only having to assert a
typecheck, which hopefully is fast?
for i=1:2:length(arr) (arr[i]::B).x end
Brendan