Hi, I'm having an issue with the syntax for modules. Basically I'm trying to split my code into two seperate files, one for the object I'm creating (AST), and one for all of my functions.
--main.hs
data AST = Add (AST) (AST)|
Sub (AST) (AST)|
Mult (AST) (AST)|
Ident Char|
Num Int
deriving Show
aSTLeft (Num l ) = (Num l)
aSTLeft (Ident l ) = (Ident l)
aSTLeft (Add l _ ) = l
aSTLeft (Sub l _ ) = l
aSTLeft (Mult l _ ) = l
aSTRight (Num r ) = (Num r)
aSTRight (Ident r ) = (Ident r)
aSTRight (Add _ r ) = r
aSTRight (Sub _ r ) = r
aSTRight (Mult _ r ) = r
isNum (Num x) = True
isNum (Ident x) = False
isNum (Add (x)(y)) = False
isNum (Sub (x)(y)) = False
isNum (Mult (x)(y)) = False
--a lot more functions here
This works fine, but when I try to split the AST datatype into a seperate file,
--ASTADT.hs
module ASTADT (AST,aSTLeft,aSTRight) where
data AST = Add (AST) (AST)|
Sub (AST) (AST)|
Mult (AST) (AST)|
Ident Char|
Num Int
deriving Show
aSTLeft (Num l ) = (Num l)
aSTLeft (Ident l ) = (Ident l)
aSTLeft (Add l _ ) = l
aSTLeft (Sub l _ ) = l
aSTLeft (Mult l _ ) = l
aSTRight (Num r ) = (Num r)
aSTRight (Ident r ) = (Ident r)
aSTRight (Add _ r ) = r
aSTRight (Sub _ r ) = r
aSTRight (Mult _ r ) = r
and
--main.hs
import ASTADT
isNum (Num x) = True
isNum (Ident x) = False
isNum (Add (x)(y)) = False
isNum (Sub (x)(y)) = False
isNum (Mult (x)(y)) = False
--a lot more functions here
Loading main.hs I get error message
Undefined data constructor "Num"
I'm pretty sure its just an issue with my module syntax, but I've been completely stuck for several hours now. I'm working with Hugs. Thanks