我想做一个wireworld移动,但是它显示了一个错误

时间:2013-04-04 12:35:56

标签: haskell parse-error

我被要求做一个线上世界的举动。所以我编写了以下代码,(代码中的所有函数都以某种方式在其他模块中定义,所以,不要担心XD,请随时问我是否要查看那些“预定义的函数”)但是当我在终端上运行它时,它显示错误,这是代码:

module Transitions.For_List_2D (
   transition_world -- :: List_2D Cell -> List_2D Cell
) where

import Data.Cell (Cell (Head, Tail, Conductor, Empty))
import Data.Coordinates
import Data.List_2D

transition_world :: List_2D Cell -> List_2D Cell
transition_world world = case world of
    (Head,(x,y)):rest-> (Tail,(x,y)): transition_world rest
    (Tail,(x,y)):rest -> (Conductor, (x, y)): transition_world rest
    (Empty, (x, y)):rest ->(Empty, (x, y)): transition_world rest
    (Conductor, (x, y)):rest
      | element_occurrence==1 || element_occurrence==2 = (Head, (x, y)): transitio
        n_world    rest
      | otherwise = (Conductor, (x, y)): transition_world rest
    [] -> []

然而,当我在终端上通过hs文件的“./”名称运行它时,它显示以下错误:

For_List_2D.hs:23:56: parse error on input '='

我完全被这个错误搞糊涂了 提前感谢任何可以帮助我的人。

1 个答案:

答案 0 :(得分:4)

这些行

  | element_occurrence==1 || element_occurrence==2 = (Head, (x, y)): transition_world    rest
  | otherwise = (Conductor, (x, y)): transition_world rest

应该是

  | element_occurrence==1 || element_occurrence==2 -> (Head, (x, y)): transition_world    rest
  | otherwise -> (Conductor, (x, y)): transition_world rest

我们在方程式(例如函数定义)中使用=,在case表达式中使用->