haskell大神,求问一道Haskell的编程题!原题是英文,我怕我翻译不到位,还是把题目po上来:Define a function called 'SquareSum' that sums the squares of a list of integers.Give the type of the function and use an anonymous funct

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/02 17:24:46

haskell大神,求问一道Haskell的编程题!原题是英文,我怕我翻译不到位,还是把题目po上来:Define a function called 'SquareSum' that sums the squares of a list of integers.Give the type of the function and use an anonymous funct
haskell大神,求问一道Haskell的编程题!
原题是英文,我怕我翻译不到位,还是把题目po上来:Define a function called 'SquareSum' that sums the squares of a list of integers.Give the type of the function and use an anonymous function and the library functions 'foldr' and ' map',but no other library functions.
意思是:定义一个函数 取名为SquareSum,将一个list的整数平方后,再都加起来算和,给出函数的类型type,并且使用使用一个匿名函数和库函数‘foldr’和’map‘,但不能使用其它库函数.

haskell大神,求问一道Haskell的编程题!原题是英文,我怕我翻译不到位,还是把题目po上来:Define a function called 'SquareSum' that sums the squares of a list of integers.Give the type of the function and use an anonymous funct
这个问题不成立, 因为(+)也是库函数 (不知道你敢不敢这样告诉你老师)
不敢的话就只好乖乖写
squaresum :: [Integer] -> Integer
squaresum nums = foldr (+) 0 (map (^ 2) nums)