我還在努力破解這個代碼:在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