我在这个简单的 haskell 代码中遇到了一个奇怪的错误。
我确认我在任何地方都使用空格并且我没有看到任何缩进问题。
我是否错过了出现此语法错误的内容?
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"
最佳答案
case 的缩进级别应该至少比 let 语句的变量名开头多一个空格,例如:
let res = case b of
Just val -> "There is a value, and it is a value"
Nothing -> "There is nothing!"
如果你写在与
res
相同的级别开始,它被解析为好像它是 let
的一部分块,而不是 case
在 let
堵塞。同样,如果你写的比
res
缩进少,它被解析为好像它是 do
的一部分块,而不是 case
.
关于haskell - 有 "parse error on input ‘->’ "的情况下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58905982/