Sum of Squares using Haskell

前端 未结 3 1868
梦毁少年i
梦毁少年i 2020-12-06 23:31

I\'m trying to carry out the following computation: sum of the squares of integers in the range x:y where (x <= y).

I\'m not sure how to put a constraint to ensur

3条回答
  •  再見小時候
    2020-12-07 00:16

    Using list comprehension:

    squareSum from to
      | from > to = error "wrong input"
      | otherwise = sum [i^2 | i <- [from..to]]
    

    UPDATE: updated after OP has updated the question

提交回复
热议问题