Haskell 为什么不是';哈斯克尔的缩进不正确吗?
为什么第5行不包含缩进错误。我希望在编译时得到一个解析错误。我希望第5行的Haskell 为什么不是';哈斯克尔的缩进不正确吗?,haskell,Haskell,为什么第5行不包含缩进错误。我希望在编译时得到一个解析错误。我希望第5行的+必须与第4行的*对齐 module Learn where x = 10 * 5 + y -- why isn't this incorrect indentation myResult = x * 5 y = 10 它编译,因为没有块要考虑。 缩进仅在where,let,do,的情况下起作用。 这些关键字开始一块东西,了解一行是继续上一个条目、开始新条目还是结束该块很重要 case f 5 of
+
必须与第4行的*
对齐
module Learn where
x = 10
* 5
+ y -- why isn't this incorrect indentation
myResult = x * 5
y = 10
它编译,因为没有块要考虑。 缩进仅在
where
,let
,do
,的情况下起作用。
这些关键字开始一块东西,了解一行是继续上一个条目、开始新条目还是结束该块很重要
case f 5 of
A -> foo
32 -- continues the previous entry
B -> 12 -- starts a new entry
+ bar 43 -- ends the case
在=
之后,我们不需要将块拆分为条目:只有一个表达式。因此没有应用。 它编译,因为没有块要考虑。
缩进仅在where
,let
,do
,的情况下起作用。
这些关键字开始一块东西,了解一行是继续上一个条目、开始新条目还是结束该块很重要
case f 5 of
A -> foo
32 -- continues the previous entry
B -> 12 -- starts a new entry
+ bar 43 -- ends the case
在=
之后,我们不需要将块拆分为条目:只有一个表达式。因此不适用。这是因为x
的定义都在x
开头的右边。每行的起始位置并不重要,只要这些行缩进到x
的右边,这就可以编译了,因为x
的定义都在x
开头的右边。只要这些行缩进到x
的右侧,每行的起始位置就不重要了