On Fri, Jan 8, 2016 at 1:12 PM, 'Jamie Brandon' via julia-users <
[email protected]> wrote:
> > Yes, it's like any other parametric type that way.
>
> Are tuples treated specially? eg:
>
Yes, tuples types are covariant while everything else is invariant.
> ANY is a hack to let you hint to the compiler that it should not
> specialize a method on an argument.
>
> That's exactly what I'm trying to achieve. I really don't want my
> array functions to specialize on the length of the array :)
>
If you don't want to specialize on the length of the array why include it
in the type at all?
> > Currently you have to use a typealias...
>
> I'm not having any luck with this.
>
> typealias Array{T} NArray{ANY,T}
>
> call{T}(t::Type{Array{T}}) = begin
> tp = pointer_from_objref(t)
> size = sizeof(t)
> ...
> end
>
> julia> arr = Hamt.NArray{10, Int64}()
> ERROR: MethodError: `convert` has no method matching
> convert(::Type{Hamt.NArray{10,Int64}})
> This may have arisen from a call to the constructor
> Hamt.NArray{10,Int64}(...),
> since type constructors fall back to convert methods.
> Closest candidates are:
> convert{T}(::Type{T}, ::T)
> Hamt.NArray{N,T}(, ::Any)
> call{T}(::Type{T}, ::Any)
> in call at essentials.jl:57
>
> julia> arr = Hamt.Array{Int64}()
> ERROR: argument is an abstract type; size is indeterminate
> in call at /home/jamie/code/imp/src/Hamt.jl:23
>
> I have this doing exactly what I want with the bare types eg:
>
> Base.getindex{T}(narray::NArray{ANY,T}, ix::Integer)
>
> I'm just struggling getting the same behaviour from the constructor
> because of the way Type varies.
So one issue here is that using ANY like this doesn't mean what you want it
to – it means that the first parameter of NArray is the literal value ANY.
So when you write call{T}(t::Type{Array{T}}) it literally means
call{T}(t::Type{NArray{ANY,T}}) – which is not what you want. Instead,
you'd want a typealias like this:
typealias TArray{T,n} NArray{n,T}
call{T}(t::Type{TArray{T}}) = ...
But I'm getting a little confused about what you're trying to accomplish
with that type parameter for the number of elements in the first place.