0

我被要求进行一次有线世界的移动。所以我写了以下代码,(代码中的所有函数都以某种方式在其他模块中定义,所以,不用担心那个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 '='

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

4

1 回答 1

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

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

于 2013-04-04T12:38:44.917 回答