이 과제를 수행하고 있습니다.이 작업을 수행하려면 필사적입니다. 이것이 가장 현명한 방법은 아니며 가장 효율적인 방법이 아니라는 것을 알고 있습니다. 이 코드가 얼마나 비효율적인지 테스트하고 싶기 때문에이 작업을 수행했습니다.Haskell에서 컴파일 할 때 Parse Error (x + 1)가 발생했습니다.
transition_from_conductor :: Element_w_Coord Cell -> List_2D Cell -> Cell
transition_from_conductor element world = case num_of_heads_around_conductor (0, element) world of
1 -> Head
2 -> Head
_ -> Conductor
where
num_of_heads_around_conductor :: (Int, Element_w_Coord Cell) -> List_2D Cell -> Int
num_of_heads_around_conductor (i, (cell, (x, y))) ((w_cell, (w_x, w_y): rest)) = case rest of
[] -> i
_ -> case (w_cell, w_x, w_y) of
(Head, (x + 1), y) -> num_of_heads_around_conductor ((i + 1), (cell, (x, y))) (rest)
(Head, (x + 1), (y + 1)) -> num_of_heads_around_conductor ((i + 1), (cell, (x, y))) (rest)
(Head, (x + 1), (y - 1)) -> num_of_heads_around_conductor ((i + 1), (cell, (x, y))) (rest)
(Head, (x - 1), y) -> num_of_heads_around_conductor ((i + 1), (cell, (x, y))) (rest)
(Head, (x - 1), (y + 1)) -> num_of_heads_around_conductor ((i + 1), (cell, (x, y))) (rest)
(Head, (x - 1), (y - 1)) -> num_of_heads_around_conductor ((i + 1), (cell, (x, y))) (rest)
(Head, x, (y + 1)) -> num_of_heads_around_conductor ((i + 1), (cell, (x, y))) (rest)
(Head, x, (y - 1)) -> num_of_heads_around_conductor ((i + 1), (cell, (x, y))) (rest)
_ -> num_of_heads_around_conductor (i , (cell, (x, y))) (rest)
내가 터미널에서 이것을 실행하려고하면, 그것은 나를 내가 잘못 했습니까 무엇
(Head, (x + 1), y) .....
에 오류 (X + 1)를 분석 할 수 있습니다? 어떻게 수정해야합니까?
몇 가지 ...
type List_2D e = [Element_w_Coord e]
type Element_w_Coord e = (e, Coord)
type Coord = (X_Coord, Y_Coord)
type X_Coord = Integer
type Y_Coord = Integer
고마워 : D
우리는 'abs (x - x') <2 && abs (y - y ') <2'라는 것을 알고 있습니까? OP의 코드를 자세히 읽지는 않았습니다. – dave4420
그리드에있는 셀의 주변 8 개 이웃을 일치시키는 것처럼 보이므로 정확한 일치에 대한 예외를 더한 것으로 충분해야합니다. – hammar