Data structure definitions

Mark T.B. Carroll
Tue, 8 Oct 2002 19:46:09 -0400 (EDT)

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