Hello I'm writing this code as a beginner Haskell project that solves a very basic version of minesweeper. Details are unimportant but I keep getting a syntax error on line 50 in the isGoal function Syntax error in expression (unexpected `;', possibly due to bad layout). This function is supposed to test if the al list is an empty list and return true if so but I keep getting this syntax error. I'm a beginner so any help is appreciated
type Cell = (Int,Int)
data MyState = Null | S Cell [Cell] String MyState deriving Show
up :: MyState -> MyState
up (S (0, _) [_] _ _)= Null
up (S (0, _) (_:_) _ _)= Null
up (S (x,y) [c] "" s)= S ((x-1),y) [c] "up" (S (x,y) [c] "" s)
up (S (x,y) [c] b s)= S ((x-1),y) [c] "up" (S (x,y) [c] b s)
up (S (x,y) (c:cs) "" s)= S ((x-1),y) (c:cs) "up" (S (x,y) (c:cs) "" s)
up (S (x,y) (c:cs) b s)= S ((x-1),y) (c:cs) "up" (S (x,y) (c:cs) b s)
down :: MyState -> MyState
down (S (3, _) [_] _ _)= Null
down (S (3, _) (_:_) _ _)= Null
down (S (x,y) [c] "" s)= S ((x+1),y) [c] "down" (S (x,y) [c] "" s)
down (S (x,y) [c] b s)= S ((x+1),y) [c] "down" (S (x,y) [c] b s)
down (S (x,y) (c:cs) "" s)= S ((x+1),y) (c:cs) "down" (S (x,y) (c:cs) "" s)
down (S (x,y) (c:cs) b s)= S ((x+1),y) (c:cs) "down" (S (x,y) (c:cs) b s)
left :: MyState -> MyState
left (S (_, 0) [_] _ _)= Null
left (S (_, 0) (_:_) _ _)= Null
left (S (x,y) [c] "" s)= S (x,(y-1)) [c] "left" (S (x,y) [c] "" s)
left (S (x,y) [c] b s)= S (x,(y-1)) [c] "left" (S (x,y) [c] b s)
left (S (x,y) (c:cs) "" s)= S (x,(y-1)) (c:cs) "left" (S (x,y) (c:cs) "" s)
left (S (x,y) (c:cs) b s)= S (x,(y-1)) (c:cs) "left" (S (x,y) (c:cs) b s)
right :: MyState -> MyState
right (S (_, 3) [_] _ _)= Null
right (S (_, 3) (_:_) _ _)= Null
right (S (x,y) [c] "" s)= S (x,(y+1)) [c] "right" (S (x,y) [c] "" s)
right (S (x,y) [c] b s)= S (x,(y+1)) [c] "right" (S (x,y) [c] b s)
right (S (x,y) (c:cs) "" s)= S (x,(y+1)) (c:cs) "right" (S (x,y) (c:cs) "" s)
right (S (x,y) (c:cs) b s)= S (x,(y+1)) (c:cs) "right" (S (x,y) (c:cs) b s)
collect:: MyState -> MyState
collect (S l [a,b] d z) | l==a = (S l [b] "collect" (S l [a,b] d z))
| l==b = (S l [a] "collect" (S l [a,b] d z))
|otherwise =Null
check:: (MyState -> MyState) -> (MyState -> [MyState])
check f (S l [a,b] d z) = if f (S l [a,b] d z) == Null then [] else f (S l [a,b] d z)
nextMyStates:: MyState -> [MyState]
nextMyStates (S l [a,b] d z) = check(up (S l [a,b] d z) ++ check(down (S l [a,b] d z) ++ check(right (S l [a,b] d z) ++ check(left (S l [a,b] d z) ++check(collect (S l [a,b] d z)
isGoal :: (MyState) -> (Bool)
isGoal (S l al d z) = if al == ([]) then True else False
search::[MyState]->MyState
search (S l al d z:xs) | isGoal S l al d z =(S l al d z)
| isGoal S l al d z ==False = search xs ++ nextMyStates (S l al d z)
constructSolution :: MyState ->[String]
constructSolution (S l c d z) | z == Null = []
| d == Null = [] ++ constructSolution (z p cs s k)
| otherwise = [d] ++ constructSolution (z p cs s k)
solve :: Cell->[Cell]->[String]
solve (x,y) [(a,b),(c,d)] = constructSolution (search (nextMyStates S (x,y) [(a,b),(c,d)] "" Null))
This is way more code than necessary to track down the error. In the future, please include full error messages (those are always useful), but narrow down the code to something more minimal. For example, you can try deleting a function and see if the error still manifests.
Nonetheless, in this case, the issue is not hard to find from the small error message we got:
nextMyStates, the function beforeisGoal, has unbalanced parentheses.