Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having "parse error on input ‘->’" in a case of

Tags:

haskell

I'm having a weird error in this simple haskell code. I confirm I'm using spaces everywhere and I don't see any problem with indentation.

Am I missing something to have this syntax error?

    it "I can play with Maybe a bit" $ do
      let b = Just "whatever"

      let res = case b of
        Just val -> "There is a value, and it is a value" --parse error on input ‘->’
        Nothing  -> "There is nothing!"

      res `shouldBe` "There is a value, and it is a value"
like image 368
Francisco Albert Avatar asked Nov 17 '19 22:11

Francisco Albert


1 Answers

The indentation level of the cases should be at least one space more than the start of the variable name of the let statement, like:

let res = case b of
     Just val -> "There is a value, and it is a value"
     Nothing  -> "There is nothing!"

If you write it on the same level as where res starts, it is parsed as if it is part of the let block, and not of the case in the let block. Similarly, if you write it less indented than res, it is parsed as if it is part of the do block, and not of the case.

like image 150
Willem Van Onsem Avatar answered Sep 30 '22 19:09

Willem Van Onsem