
I think this is more or less the standard way of doing it. I don't think type classes are the right thing to do. Usually constructors are prefixed with the first character of their type in situations like this (or so I've seen), so you get: data Expression = EValue Value | EVariable Variable | ... data Value = VNumber Number | V... | ... etc... I'm not sure if this answers your question or not, tho... -- Hal Daume III "Computer science is no more about computers | hdaume@isi.edu than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume On Tue, 8 Oct 2002, Mark T.B. Carroll wrote:
I have a program that basically has,
data Expression = Value Value | EVariable Variable | other stuff ...
data Value = VNumber Number | other stuff ...
data Variable = Variable { variable_name :: String, variable_time :: Expression } data Number = Number { value :: Double, dimension :: Dimension }
newtype VariableCount = VariableCount (Variable, Number)
The VNumber and EVariable constructors are ugly, though, so I was wondering if I should be using typeclasses - e.g.,
class Expression a class Expression a => Value a instance Value Number instance Expression Variable
... but I don't see how to define Variable in such a scheme. Maybe I shouldn't be using typeclasses?
(Obviously, I actually have lots more type constructors in Expression and Value - dyadic expressions, booleans, etc. - the above with just numbers and variables is somewhat truncated, but should suffice.)
-- Mark
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe