I'm new to Haskell. This is the code which I made:
transition_world world = case world of
(Head,(x,y)):cs-> (Tail,(x,y)): transition_world cs
(Tail,(x,y)):cs -> (Conductor, (x,y)): transition_world cs
(Empty, (x,y)):cs -> (Empty, (x,y)): transition_world cs
(Conductor, (x,y)):cs
| element_occurrence Head == 1 || element_occurrence Head == 2
-> (Head, (x,y)): transition_world cs
| otherwise -> (Conductor, (x,y)): transition_world cs
[] -> []
While trying to compile, GHCi gives me this error:
Sources\Transitions\For_List_2D.hs:23:33:
No instance for (Eq (List_2D Cell -> Data.Integer_Subtypes.Nat))
arising from a use of `=='
Possible fix:
add an instance declaration for
(Eq (List_2D Cell -> Data.Integer_Subtypes.Nat))
In the first argument of `(||)', namely
`element_occurrence Head == 1'
In the expression:
element_occurrence Head == 1 || element_occurrence Head == 2
In a stmt of a pattern guard for
a case alternative:
element_occurrence Head == 1 || element_occurrence Head == 2
Sources\Transitions\For_List_2D.hs:23:36:
No instance for (Num (List_2D Cell -> Data.Integer_Subtypes.Nat))
arising from the literal `1'
Possible fix:
add an instance declaration for
(Num (List_2D Cell -> Data.Integer_Subtypes.Nat))
In the second argument of `(==)', namely `1'
In the first argument of `(||)', namely
`element_occurrence Head == 1'
In the expression:
element_occurrence Head == 1 || element_occurrence Head == 2
Can't understand what does it want from me... Where did I make a mistake? And how can I fix it?
Extra 1:
element_occurrence :: Eq e => e -> List_2D e -> Nat
element_occurrence element list = case list of
(local_element, _): cs
| local_element == element -> 1 + element_occurrence element cs
| otherwise -> element_occurrence element cs
[] -> 0
Extra 2:
local_elements :: Coord -> List_2D e -> List_2D e
local_elements (x, y) list = read_neighbours (x, y) 1 list
where
read_neighbours :: Coord -> Distance -> List_2D e -> List_2D e
read_neighbours (x, y) dist list = case list of
(element, (x_e, y_e)): cs
| abs (x_e - x) <= dist
&& abs (y_e - y) <= dist -> (element, (x_e, y_e)): read_neighbours (x, y) dist cs
| otherwise -> read_neighbours (x, y) dist cs
[] -> []
local_elements_list :: Coord -> List_2D e -> [e]
local_elements_list (x, y) list = read_neighbours_list (x, y) 1 list
where
read_neighbours_list :: Coord -> Distance -> List_2D e -> [e]
read_neighbours_list (x, y) dist list = case list of
(element, (x_e, y_e)): cs
| abs (x_e - x) <= dist
&& abs (y_e - y) <= dist -> element: read_neighbours_list (x, y) dist cs
| otherwise -> read_neighbours_list (x, y) dist cs
[] -> []
size :: List_2D e -> Nat
size list = case list of
[] -> 0
_: xs -> 1 + size xs
element_occurrence? Anyway, the error tells you that ghc don't know how to compare a value of typeList_2D Cell -> Data.Integer_Subtypes.Nat(which is a function) to 1. The expressionelement_occurrence Headis probably missing an argument.