help wanted with type error message
Norman Ramsey
nr@eecs.harvard.edu
Wed, 4 Apr 2001 11:59:17 -0400
I'm learning Haskell, and I'm having trouble understanding the meaning
of a `context' as applied to the declaration of an algebraic datatype.
I would like to say the following:
A formula is a predicate over environments.
> class Formula f where
> eval :: f a -> Environment a -> Bool -- evaluate the formula
> eq :: Var -> a -> f a -- basic equality
> (&) :: f a -> f a -> f a -- conjunction
> type Environment a = Var -> a
> type Var = String
A row has a formula and a weight.
> data Formula f => Row a = Row (f a, Weight)
> type Weight = Float
Hugs rejects this program:
ERROR "hard.lhs" (line 14): Undefined type variable "f"
Line 14 is the definition of Row. Can anyone explain the proper
use of a context in a data definition?
Thanks,
Norman