Hi,

I'm a bit confused on why the follow code fails:

abstract Country
immutable US  <: Country;  pct::Real end
immutable CA  <: Country;  pct::Real end
immutable DE  <: Country;  pct::Real end

abstract AbstractAsset{Listed<:Country,Origin<:Country}    # line 6
type Stock{Listed,Origin} <: AbstractAsset{Listed,Origin}
  listed::Type{Listed} # the country of the exchange (where it was 
purchased)
  origin::Type{Origin} # the country the stocks are from
end

type Account{A<:AbstractAsset} # line 12
  holdings::AbstractVector{A}
end

for stocks in Any[[Stock(US,US)], [Stock(US,US), Stock(US,US)], [Stock(CA, 
US), Stock(CA, CA)]] # line 16
  @show typeof(stocks)
  Account(stocks)
end


The error output is:

typeof(stocks) => Array{Stock{US,US},1}
typeof(stocks) => Array{Stock{US,US},1}
typeof(stocks) => Array{Stock{Listed,Origin},1}
ERROR: `Account{A<:AbstractAsset{Listed<:Country,Origin<:Country}}` has no 
method matching 
Account{A<:AbstractAsset{Listed<:Country,Origin<:Country}}(::Array{Stock{Listed,Origin},1})
 in anonymous at no file:18
 in include at ./boot.jl:245
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:285
 in _start at ./client.jl:354
while loading type_of_types.jl, in expression starting on line 16



The fix seems to be to change line 7 to:

type Stock{Listed<:Country,Origin<:Country} <: AbstractAsset{Listed,Origin}

then the output is:

typeof(stocks) => Array{Stock{US,US},1}
typeof(stocks) => Array{Stock{US,US},1}
typeof(stocks) => Array{Stock{Listed<:Country,Origin<:Country},1}

These changes to line 7 would seem to be redundant because Listed and 
Origin already must be a Country because of line 6 -- I tested setting 
"Stock.listed" to a currency and it indeed fails (as expected because of 
line 6).  I get confused about how the parametric types resolve their types 
and I feel that I'm missing some key concept.  Can someone help me 
understand what is going on here?  Debugging "has no method matching" 
errors comes up quite often for me.

Thanks,

Glen

Reply via email to