简体   繁体   中英

Haskell code to compute sum of squares of negative integers using foldr function

I am new to haskell code. I tried to compute the sum of squares of negative integer in a list using foldr high order.

  sumsq :: Int -> Int
  sumsq n = foldr op 0 [1..n]
  where op x y = x*x + y

Please help to explain each line of code and give any solution if error in this code

When using "where", important to follow the indentation rule. Here lambda will be appropriate

sumsq n = foldr (\x y -> x*x + y) 0 [1..n]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM