我正在尝试为方向定义新的数据类型.但是,当我在ghci中加载文件时,我收到错误"Not a data constructor:left".
这是代码片段:
data Dir = left | right | up | down instance Show Dir where show left = "left" show right = "right" show up = "up" show down = "down" -- initialpos is assumed to be valid one move::Pos->Dir->Pos move prevPos left = ( (-1) $ fst prevPos , snd prevPos) move prevPos right = ( (+1) $ fst prevPos , snd prevPos ) move prevPos up = ( fst prevPos, (+1) $ snd prevPos ) move prevPos down = ( fst prevPos, (-1) $ snd prevPos )
请帮我弄清楚出了什么问题.
忽略中缀数据构造函数,数据构造函数必须以大写字母开头.
data Dir = Left | Right | Up | Down