We're a place where coders share, stay up-to-date and grow their careers.
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)
[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
Point free baby!
(Obviously this is probably too polymorphic, you could just limit it to
[Int] -> Int
)How about this?
Also point free and a bit easier on the eye. If we want to keep it single traversal, maybe