And Julia is quite comfortable with using *type_parameter[s] *to guide or
to fully direct multiple dispatch;
so in the second of the preceding approaches, you could eliminate the
direction::D field from the type, keeping the D<:Direction parameter
and your functions (Base.plus etc) would do the right thing if you made a
ForwardDirection and a BackwardDirection version for each needed.
Where that sort of apportionment greatly simplifies or clarifies
implementation, it is available.
On Thursday, September 10, 2015 at 11:39:29 AM UTC-4, Tim Wheeler wrote:
>
> Julia only supports concrete leaves in the type tree - all non-leaves
> (parents) must be abstract types.
>
> You should be able to do:
>
> abstract AbstractDataStream{T <: Number}
>
> type DirectedDataStream{T <: Number} <: AbstractDataStream{T}
> data::Vector{T}
> stuff
> end
>
> type ReversedDataStream{T <: Number} <: AbstractDataStream{T}
> data::Vector{T}
> stuff
> end
>
> Another thing you can do that still leverages multiple dispatch is define
> the reversal as a separate type:
>
> abstract Direction
> type ForwardDirection <: Direction end
> type BackwardDirection <: Direction end
>
> type MyDataStream{T<:Number, D<:Direction}
> data::Vector{T}
> direction::D
> stuff
> end
>
> Base.plus{T<:Number, S<:Number, D<:ForwardDirection}(a::MyDataStream{T,D},
> b::MyDataStream{S,D}) ...
> Base.plus{T<:Number, S<:Number, D<:BackwardDirection}(a::MyDataStream{T,D
> }, b::MyDataStream{S,D}) ...
>
>
>