[Haskell-beginners] New to Haskell: constructing Data Types

Tyler Hayes tgh at pdx.edu
Sat Feb 5 05:33:26 CET 2011


As an exercise, I'm attempting to create an abstract syntax tree for a
very small language:

data Expression = Variable String
                | Integer
                | Expression BinOp Expression
                deriving Show

data Statement = Assignment Variable Expression	   --error!
               | If Expression Statement Statement
               | While Expression Statement
               | Compound Statement
               deriving Show

data BinOp = Add
           | Mult
           | LessThan
           | GreaterThan
           deriving Show

However, there is a problem with having "Variable" as an argument to the
"Assignment" constructor of the "Statement" data type:

Prelude> :l test.hs 
[1 of 1] Compiling Test              ( test.hs, interpreted )

test.hs:8:28: Not in scope: type constructor or class `Variable'
Failed, modules loaded: none.

An 'assignment' is a variable followed by an expression in this example,
so what can I do to fix this?

Thanks,
Tyler




More information about the Beginners mailing list