[英]Haskell code to compute sum of squares of negative integers using foldr function
我是 haskell 代碼的新手。 我嘗試使用 foldr 高階計算列表中負 integer 的平方和。
sumsq :: Int -> Int
sumsq n = foldr op 0 [1..n]
where op x y = x*x + y
請幫助解釋每一行代碼,如果此代碼有錯誤,請給出任何解決方案
使用“where”時,遵循縮進規則很重要。 這里 lambda 會合適
sumsq n = foldr (\x y -> x*x + y) 0 [1..n]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.