Haskell parse error on input '|'

2019-05-21 01:23发布

问题:

I'm getting the following error:

parse error on input '|'

with my code:

makeMove :: Player -> Board -> Maybe Board
makeMove p b | hasWinner b == Nothing = getMove p rb ri
                                        where rb = gameTree p b
                                              ri = minimax p rb
                                              ros2int (i' :> ri') = i'
                                              rb2b (b':rbs') = b
                                              getMove p (r:rs) (i:is) = let bs  = map rb2b rs
                                                                            is  = map ros2int is
                                                                            idx = elemIndex (maximum' is) is
                                                                            res (Nothing) = Nothing
                                                                            res (Just x) = Just ((bs)!!x)
                                                                        in res idx
              | otherwise = Nothing

However I suppose this would be caused by tabs interference usually but I checked and I only used spaces so that couldn't be the problem. Could anyone help me out on this?

Thanks in advance!

Best regards, Skyfe.

回答1:

The where clause should be after all guards:

fun a b 
  | one = ...
  | oterwise = ...
  where ....