loading...

re: Daily Challenge #225 - Square'n'Sum VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Point free baby! import Data.Monoid (Sum(..)) squareSum :: (Num c, Foldable t) => t c -> c squareSum = getSum . foldMap (Sum . (^2)) (...
 

How about this?

squareSum :: [Int] -> Int
squareSum = sum . fmap (^2)

Also point free and a bit easier on the eye. If we want to keep it single traversal, maybe

squareSum = foldr ((+) . (^2)) 0
code of conduct - report abuse