HI,

Coming from the Python world is a big step, especially when dealing with 
parametric types and their constructors. But Julia looks so promising and 
it is so fun to code with that i do not give up. I have an issue, though.

Say I define the following parametric type:
type FieldObj{R}
    data::Array{Float64, R}
    meta::Dict{ASCIIString, Union(Int64, Float64)}
    N::Int64
    rank::Int64
    function FieldObj(data::Array{Float64, R}, meta::Dict{ASCIIString, 
Union(Int64, Float64)})
        new(data, meta, size(data, R), R-2)
    end
end

function FieldObj{R}(data::Array{Float64, R}, meta::Dict{ASCIIString, 
Union(Int64, Float64)})
    FieldObj{R}(data, meta)
end

function FieldObj{R}(data::Array{Float64, R})
    FieldObj{R}(data, default_meta())
end
where the parameter R specifies the dimension of the array data. (Is this 
possible at all??)

I can now instantiate objects as
phi = FieldObj{2}(ones(100, 100))
ok. 

However, i want to define some  typealiases, to have a nicer interface, and 
because operators will have a different meaning for each R. Say the 
typealiases are:
typealias ScalarField FieldObj{2}
typealias VectorField FieldObj{3}

With these aliases I cannot directly create new objects and I get
julia> phi = ScalarField(ones(100, 100))
ERROR: no method FieldObj{2}(Array{Float64,2})

However, if I define explicitly the constructors for the typealiases this 
is possible, say I define:
 function ScalarField(data::Array{Float64, 2})
    FieldObj{2}(data, default_meta())
end
which works.

Now, I have two questions:
1) Is there a way to avoid defining all the constructors explicitly by 
hand, say with an @eval block? 
2) Why do I need to define these at all? What is "exactly" a typealias then?

Thank you.

Davide





Reply via email to