Re: Data structure definitions

2002-10-09 Thread Johan Nordlander

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, [...]


For comparison, the example could be formulated in O'Haskell as follows:

   data Variable = Variable { variable_name :: String, variable_time :: 
Expression }
   data Number = Number { value :: Double, dimension :: Dimension }

   data Value  Number = other stuff

   data Expression  Value, Number = other stuff

   newtype VariableCount = VariableCount (Variable, Number)

-- Johan

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: Data structure definitions

2002-10-09 Thread Johan Nordlander

Johan Nordlander wrote:

 For comparison, the example could be formulated in O'Haskell as 
 follows:

   data Variable = Variable { variable_name :: String, variable_time :: 
 Expression }
   data Number = Number { value :: Double, dimension :: Dimension }

   data Value  Number = other stuff

   data Expression  Value, Number = other stuff

   newtype VariableCount = VariableCount (Variable, Number)

 -- Johan

Ahem, it was brought to my attention that O'Haskell doesn't support 
Haskell's named datatype fields, which I should be the first to know... 
  I got a little carried away, it seems :-)

So I'm rephrasing my example into

   data Variable = Variable String Expression
   data Number = Number Double Dimension

   data Value  Number = other stuff

   data Expression  Value, Number = other stuff

   newtype VariableCount = VariableCount (Variable, Number)

Apologies,
Johan

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Data structure definitions

2002-10-08 Thread Mark T.B. Carroll

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
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: Data structure definitions

2002-10-08 Thread Hal Daume III

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| [EMAIL PROTECTED]
  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
 [EMAIL PROTECTED]
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe