Thanks for the explanation!  Although I think I understand your answer, I'm 
not sure how to define the types to accomplish my goal.

* a Token should have two parts, a container and a semitoken, both abstract

* an SDToken should be a specialization of Token in which the container 
portion is SortedDict{K,D} for a specific K,D and the semitoken portion is 
IntSemiToken (both parts concrete)

* Some functions take SDToken's as input.  These should be generic, i.e., 
work for all choices of K,D.

* There are also generic functions that return SDTokens as output (in which 
K and D are determined from the input args).

Can I write typealias SDToken{K,D} Token{SortedDict{K,D},IntSemiToken}?  I 
tried this and got an unexpected error message:

ERROR: type: test1: in apply, expected Function, got 
Type{Token{SortedDict{K,D},
IntSemiToken}}
 in test1 at 
c:\Users\vavasis\Documents\Projects\qmg21\julia\testnestparam.jl:32

(No 'apply' in my code!)  And in any case, even if I could write this, I'm 
not sure it solves the problem.

-- Steve



On Tuesday, October 7, 2014 2:15:01 AM UTC-4, Jutho wrote:
>
> 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