changecolour :: SquareWorld -> SquareWorld
changecolour squareWorld =
let
old_cell = theWorld squareWorld
old_cellstate = cellState old_cell
new_cellstate =nextCellState (old_cellstate (x : xs))
new_cell = old_cell { old_cellstate = new_cellstate}
newsquareWorld = squareWorld { old_cell = new_cell}
in
newsquareWorld
data Cell = Cell {cellPosition :: Coord, cellState :: CellState}
deriving (Show, Eq)
nextCellState :: CellState -> CellState
nextCellState (CellState (_ :< xs)) = CellState xs
data SquareWorld = SquareWorld { theAnt :: Ant, theWorld :: [Cell]}
deriving Show
错误消息是:
[12 of 14]编译StudentSources.LangtonsAnt(src / StudentSources / LangtonsAnt.hs,build / x86_64 / StudentSources / LangtonsAnt.o)
src / StudentSources / LangtonsAnt.hs:154:50:不在范围内:'x'
src / StudentSources / LangtonsAnt.hs:154:54:不在范围内:'xs'
的src / StudentSources / LangtonsAnt.hs:155:27: 'old_cellstate'不是(可见)构造函数字段名称
的src / StudentSources / LangtonsAnt.hs:156:36: 'old_cell'不是(可见)构造函数字段名称
我该怎么办?
答案 0 :(得分:1)
new_cell = old_cell { old_cellstate = new_cellstate}
应该是
new_cell = old_cell { cellState = new_cellstate}
您必须使用=
符号左侧字段的名称,而不是所述字段的上一个值。该字段的名称是data T = K { fieldName :: Type , ... }
声明中使用的字段。
squareWorld
存在类似问题。