loading...

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

FULL DISCUSSION
 

Point free baby!

import Data.Monoid (Sum(..))

squareSum :: (Num c, Foldable t) => t c -> c
squareSum = getSum . foldMap (Sum . (^2))

(Obviously this is probably too polymorphic, you could just limit it to [Int] -> Int)

 

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