和我上一个问题一样,我要求通过有序列表制作一个有线世界,所以我编写了以下代码,(代码中的所有功能都在其他模块中以某种方式定义,所以,不用担心 XD,随意问我是否想看看那些“预定义的函数”)但是当我在终端上运行它时,它显示一个错误,这里是代码:
module Transitions.For_Ordered_Lists_2D (
transition_world -- :: Ordered_Lists_2D Cell -> Sparse_Line Cell
) where
import Data.Cell (Cell (Head, Tail, Conductor, Empty))
import Data.Coordinates
import Data.Ordered_Lists_2D
-- Replace this function with something more meaningful:
xandy :: Element_w_Coord Cell -> Coord
xandy (e, (x, y)) = (x, y)
transition_sc :: Ordered_Lists_2D Cell -> Placed_Elements Cell -> Sparse_Line Cell
transition_sc world pec = case world of
Sparse_Line{y_pos = y, entries = xline}: rest_of_sparse_lines -> case pec of
Placed_Element{x_pos = x, entry = Head} : rest_of_placed_elements -> (Sparse_Line{y_pos = y, entries = Placed_Element{x_pos = x, entry = Tail} : rest_of_placed_elements})
Placed_Element{x_pos = x, entry = Tail} : rest_of_placed_elements -> (Sparse_Line{y_pos = y, entries = Placed_Element{x_pos = x, entry = Conductor} : rest_of_placed_elements})
Placed_Element{x_pos = x, entry = Empty} : rest_of_placed_elements -> (Sparse_Line{y_pos = y, entries = Placed_Element{x_pos = x, entry = Empty} : rest_of_placed_elements})
Placed_Element{x_pos = x, entry = Conductor} : rest_of_placed_elements
|element_occurrence Head neighbours == 1 || element_occurrence Head neighbours == 2 -> (Sparse_Line{y_pos = y, entries = Placed_Element{x_pos = x, entry = Head} : rest_of_placed_elements})
|otherwise -> (Sparse_Line{y_pos = y, entries = Placed_Element{x_pos = x, entry = Conductor} : rest_of_placed_elements})
where
neighbours = local_elements (xandy (Conductor, (x, y))) world
transition_world :: Ordered_Lists_2D Cell -> Ordered_Lists_2D Cell
transition_world world = fmap (transition_sc world) world
--the end
--the end
--the end
但是它向我显示了以下错误:
u5363876@n114lt20:~/Desktop/lalal$ ./make_Wireworld
[10 of 20] Compiling Transitions.For_Ordered_Lists_2D ( Sources/Transitions/For_Ordered_Lists_2D.hs, x86_64/Transitions/For_Ordered_Lists_2D.o )
Sources/Transitions/For_Ordered_Lists_2D.hs:35:53:
Couldn't match expected type `Placed_Elements Cell'
with actual type `Sparse_Line Cell'
Expected type: [Placed_Elements Cell]
Actual type: Ordered_Lists_2D Cell
In the second argument of `fmap', namely `world'
In the expression: fmap (transition_sc world) world
我完全被这个错误弄糊涂了 提前感谢任何可以帮助我的人。
@dave4420 这里是 Placed_Elements 和 Sparse_Lines 的定义
type Ordered_Lists_2D e = [Sparse_Line e]
data Sparse_Line e = Sparse_Line {y_pos :: Y_Coord, entries :: Placed_Elements e}
data Placed_Element e = Placed_Element {x_pos :: X_Coord, entry :: e}
type Placed_Elements e = [Placed_Element e]