On Thu, Jul 14, 2016 at 12:41 PM, David Barton <[email protected]> wrote:
> Hi,
>
> I'm trying to write a function that accepts a vector of values that are of
> the same (overall) type but with different parameterisations. As a simple
> example, consider the vector = [Dict("a"=>1), Dict("b"=>1.0)]. I can easily
> use a function along the lines of
>
> function myfunc(vec::Vector{Dict})
> # do something
> end
>
> but I'd like to be able to restrict the parameterisation slightly so that
> the first parameter of the Dict type is an ASCIIString (not my actual use
> case but follows exactly the same pattern). I've tried doing something like
>
> function myfunc{T}(vec::Vector{Dict{ASCIIString, T}})
> # do something
> end
>
> but this seems to enforce the condition that all the Dicts in the vector
> have the same parametric type T (so my example of myfunc([Dict("a"=>1),
> Dict("b"=>1.0)]) fails). Is there any way of expressing this constraint? Or
The issue is the type of `[Dict("a"=>1), Dict("b"=>1.0)]` It has type
`Vector{Dict{String}}` which cannot be matched by the signature you
provide. I'm not sure if there's currently a clean way to be able to
match this type in additional to the more strict types.
> will I just have to use the first form of myfunc with some extra checking in
> the function body?
>
> Thanks
> David