Hi to everybody,

  I'm trying to implement a set of types in Julia, but I fear my C++ 
background is leading me to a wrong path. I want to define a type, 
DataStream which is basically a vector of numbers with some metadata 
associated with it. The order of the elements in the vector is important, 
because the instrument that measures such data can order them in two ways: 
let's say that they can be saved either in direct or reverse order (things 
are more complicated, but this is the point). There are many operations 
that I want to do with DataStream:

   1. Combine two of them by means of mathematical operations (in this 
   case, mixing two DataStreams with different orderings should be forbidden);
   2. Transform the ordering of one datastream into another and vice versa;
   3. Finally, there is a class of operations which can be applied to any 
   DataStream, regardless of its ordering.

My question is: what is the best, "Julian" way to implement DataStream? I 
was thinking of defining three types:

type DataStream{T <: Number}
    data :: Vector{T}
    # Put other variables here
end

type DirectDataStream{T <: Number} <: DataStream{T}
end

type ReverseDataStream{T <: Number} <: DataStream{T}
end

and then implement each function using the proper typing. This would have 
the advantage that the compiler itself should check if the operations on 
DataStream objects are compatible with their ordering.

Unfortunately, this makes the compiler complain because, as far as I 
understand from Julia's source code 
(https://github.com/JuliaLang/julia/blob/master/src/toplevel.c#L639), the 
base type (DataStream{T}) is not abstract. A solution would be to add a 
@enum member to DataStream which specifies the ordering, but in this case I 
should manually check if the ordering is ok or not in the implementation of 
every function. Is there a way to implement DataStream which is able to 
maximally exploit Julia's type system?

Thanks a lot,
  Maurizio.

Reply via email to