I'm having an issue with type in functions, I've managed to write the minimal code that explains the problem:
immutable Inner{B<:Real, C<:Real}
a::B
c::C
end
immutable Outer{T}
a::T
end
function g(a::Outer{Inner})
println("Naaa")
end
inner = Inner(1, 1)
outer = Outer(inner)
g(outer)
Will lead to the method error
MethodError: no method matching g(::Outer{Inner{Int64,Int64}})
So basically, I don't want to have to say what the types of Inner are, I just want the function to make sure that it's an Outer{Inner}
and not Outer{Float64}
or something.
Any help would be appreciated
Type
Inner{Int64,Int64}
is a concreteInner
type and it's not a subtype ofInner{Real, Real}
, since different concrete types ofInner
(Int64 or Float64) can have different representations in memory.According to the documentation, function
g
should be defined as:so it can accept all arguments of type
Inner
.Some examples, after define
g
with<:
:More details at the documentation: Parametric Composite Type