【发布时间】:2015-10-08 00:12:23
【问题描述】:
在 haskell 中工作,发现奇怪的行为,将其剥离为裸露的骨头
这个作品
a :: Bool
a = case True of
True -> True
False -> False
但是当我尝试时
b :: IO Bool
b = do
let b' = case True of
True -> True
False -> False
return b'
我明白了
ghci>:l test.hs
[1 of 1] Compiling Main ( test.hs, interpreted )
test.hs:16:14: parse error on input ‘->’
Failed, modules loaded: none.
所以我试试
c :: IO Bool
c = do
let c' = case True of
True -> True
False -> False
return c'
这行得通。
什么?为什么?为什么在这种情况下我需要一个额外的缩进?我在这方面找不到任何东西,可能是因为这些关键字在日常语言中是如此简短和常见。是否有一些规范可以解释这种行为?
【问题讨论】:
-
let块的缩进级别从let之后的第一个非空白字符开始。所以True被解释为let块中的一个子句;多一个空间会让你进入case块
标签: haskell indentation do-notation