我还在努力破解这个代码:在Haskell中,为什么我必须在这段代码中使用美元符号?
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
在problem_8 x = maximum . map product . groupsOf 5 $ x
为什么不能把它仅仅是groupsOf 5×? 是因为x后来会扩展到其他一些表达式(这里是:digits = map digitToInt $concat $ lines t
)?这就是所谓的懒惰(x现在不会扩大,但也许以后)?
谢谢。你是什么意思:既然。 (函数组合)以两个函数作为参数,?在“groupsOf 5”中,5被认为是一个函数? – osager
无论如何,非常适合指出点预期的功能,而不是列表或任何数据类型的东西。 – osager
不,'(groupsOf 5)'是一个函数 – bdonlan