I don't see the problem regarding point one.

A type with parameters, as your SortedDict{D,K}, becomes an abstract type 
when the parameters are unspecified, e.g. SortedDict, but this is indeed 
printed/formatted with unspecified parameters put back (I guess with the 
name as you defined them), e.g. as SortedDict{D,K}.

Regarding point 2, this relates to the invariance of parametric types. 

isa(t2,Token{SortedDict, IntSemiToken})
will return false, because
Token{SortedDict{Int64,ASCIIString},IntSemiToken} <: Token{SortedDict, 
IntSemiToken}
is false. There are many discussions regarding this both on the forum and I 
guess in the manual. Search for invariance versus covariance of parametric 
types.


Op dinsdag 7 oktober 2014 04:42:12 UTC+2 schreef [email protected]:
>
> 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