在下面的代码中,我可以将最后一个短语放在in
在前。它会改变什么吗?
另一个问题:如果我决定把in
最后一个短语前面需要缩进吗?
我尝试不缩进并拥抱抱怨
do {...} 中的最后一个生成器必须是表达式
import Data.Char
groupsOf _ [] = []
groupsOf n xs =
take n xs : groupsOf n ( tail xs )
problem_8 x = maximum . map product . groupsOf 5 $ x
main = do t <- readFile "p8.log"
let digits = map digitToInt $concat $ lines t
print $ problem_8 digits
Edit
好吧,所以人们似乎不明白我在说什么。让我重新表述一下:
鉴于上述上下文,以下两个是否相同?
1.
let digits = map digitToInt $concat $ lines t
print $ problem_8 digits
2.
let digits = map digitToInt $concat $ lines t
in print $ problem_8 digits
关于声明的绑定范围的另一个问题let
: 我读here http://www.haskell.org/tutorial/patterns.html that:
where
条款。
有时,在多个受保护的方程上设置绑定范围很方便,这需要一个 where 子句:
f x y | y>z = ...
| y==z = ...
| y<z = ...
where z = x*x
请注意,这不能使用 let 表达式来完成,let 表达式的范围仅限于表达式它所包含的.
我的问题:所以,可变数字对于最后一个打印短语不应该是可见的。我在这里错过了什么吗?