According to Julia's doc, either types or integers can be used as 
parameters in parametric types. In the case of integers used as parameters, 
the integers are considered as types. Nevertheless, I have found the usage 
of integer parameters to be somewhat more ambiguous. Let me elaborate.

Case 1:

type T01{n}
  x::Array{Float64, n-1}
end

Here *n* is regarded as a type and the following error is thrown:

ERROR: `-` has no method matching -(::Type{n}, ::Int64)

Case 2:

type T02{n}
  x

  function T02()
    new(Array(Float64, n-1))
  end
end

Here, *n* is regarded as an integer and the following works:

julia> t = T02{3}()
T02{3}([3.2593855673017e-311,6.365987373e-314])

julia> t.x
2-element Array{Float64,1}:
 3.25939e-311
 6.36599e-314

So, when *n* appears in the specification of field types, it is interpreted 
as a type. On the other hand, when *n* appears in an inner constructor, it 
is interpreted as an integer.

My question is this; via which mechanism Julia manages to access the value 
of the integer parameter *n* in the inner constructor? The reason I am 
asking this question is because it will enable me to make the first example 
work, which throws the error because it views *n* as a type.

A relevant third example is this (the following is pseudocode):

NewType{0} -> Float64
NewType{n} -> Array{Float64, n}, for n = 1, 2, ...

So, in this example I want to define a new parametric type *NewType*, which 
is a *Float64* when n = 0 and *Array{Float64, n} *when n = 1, 2, ...

I am afraid that it is impossible to make examples 1 and 3 work in Julia 
without ending up defining the desired types at a lower level in C and then 
returning a C pointer *jl_datatype_t **?

Reply via email to