On Thu, Apr 28, 2016 at 7:13 PM, Ben Ward <[email protected]> wrote: > The only way I've come up with so far is with this clunky looking type > union: > > intsAndVecs = Union{Unsigned, > AbstractVector{UInt8}, > AbstractVector{UInt16}, > AbstractVector{UInt32}, > AbstractVector{UInt64}, > AbstractVector{UInt128}}
You can constraint the type in the constructor instead. https://github.com/JuliaLang/julia/issues/15791#issuecomment-207060094 > > > On Thursday, April 28, 2016 at 11:44:14 PM UTC+1, Ben Ward wrote: >> >> Hi, I'm tying to create a parametric type which can hold a variable which >> could be any kind of vector, and whatever the vector is, it can store one of >> the UInts. So it could have: >> >> UInt8[1,2,3] >> UInt64[1,2,3] >> UnitRange(1, 3) >> UnitRange(UInt16(1), UInt16(3)) >> ... and so on. >> >> But I'm having trouble deciding what needs to go in the parametric part of >> it's definition: e.g. >> >> MyType{T <: (unsure of this bit)} >> val::T >> end >> >> >> I thought that AbstractVector{Unsigned} might be the way to go, but >> Vector{UInt8} does not inherit from AbstractVector{Unsigned}. >> >> Thanks, >> Ben.
