The code below is an excerpt from a more complicated code I am writing.  It 
contains a parametrized type in which the parameter is itself another 
parametrized type. I have attached the printout (0.4.0-dev+323).  Notice 
the error message at the end.  My questions are:

(1) How is it possible that the type of t includes dummy parameters K and 
D, which aren't real types at all?

(2) Why is Julia not able to match t2 but it is able to match t to the 
signature of test0()?  

Thanks,
Steve Vavasis


julia> testnestparam.test1()
typeof(t) = Token{SortedDict{K,D},IntSemiToken}
typeof(t2) = Token{SortedDict{Int64,ASCIIString},IntSemiToken}
methods(test0) = # 1 method for generic function "test0":
test0(i::Token{SortedDict{K,D},IntSemiToken}) at 
c:\Users\vavasis\Documents\Projects\qmg21\julia\testnestparam.jl:28
ERROR: `test0` has no method matching 
test0(::Token{SortedDict{Int64,ASCIIString},IntSemiToken})
 in test1 at 
c:\Users\vavasis\Documents\Projects\qmg21\julia\testnestparam.jl:38


module testnestparam

immutable IntSemiToken
    address::Int
end

immutable Token{T, S}
    container::T
    semitoken::S
end

# take a token apart
semi(i::Token) = i.semitoken
container(i::Token) = i.container

# put a token back together
assemble(m, s) = Token(m,s)

type SortedDict{K, D} <: Associative{K,D}
    bt::Dict{K,D}
end

typealias SDToken Token{SortedDict, IntSemiToken}

sdtoken_construct(m::SortedDict,int1::Int) = 
    SDToken(m, IntSemiToken(int1))

test0(i::SDToken) = nothing

function test1()
    s = SortedDict([1=>"a",2=>"b"])
    t = sdtoken_construct(s, 0)
    t2 = assemble(t.container, t.semitoken)
    println("typeof(t) = ", typeof(t))
    println("typeof(t2) = ", typeof(t2))
    println("methods(test0) = ", methods(test0))
    test0(t)
    test0(t2) #Line 38
end

end

Reply via email to