I encountered a problem whilst trying to use guards within guards in Haskell, I tried finding out if it was(n't) possible to even do so but I couldn't find any answers on the Internet, I was hoping you guys might know the answer. This is the error I'm getting while trying to compile my code:
Assignment2.hs:134:75: parse error on input '|'
verticals :: Board -> (Row, Row, Row) verticals ((a,b,c),(d,e,f),(g,h,i)) = ((a,d,g),(b,e,h),(c,f,i)) symbolToPlayer :: Field -> Player symbolToPlayer X = P1 symbolToPlayer O = P2 showTime :: Board -> Maybe Player showTime ((a,b,c),(d,e,f),(g,h,i)) | a==b && a==c = Just (symbolToPlayer a) | d==e && d==f = Just (symbolToPlayer d) | g==h && g==i = Just (symbolToPlayer i) | otherwise = False hasWinner :: Board -> Maybe Player hasWinner b@((a,b,c),(d,e,f),(g,h,i)) | showTime b -> spot of error | showTime (verticals b) | a==e && a==i = Just (symbolToPlayer a) | c==e && c==g = Just (symbolToPlayer c) | otherwise = Nothing
The code is for a game of tic-tac-toe, this part of the code is supposed to find out which player has won; the type Board is self-defined, example of input: hasWinner ((X,O,X),(X,O,O),(X,X,O)) (the output should be: Just P1).
Thanks for the help!