Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
Last active June 16, 2016 12:13
Show Gist options
  • Save simonewebdesign/6eebc9a2a344f3bdba39b279b8f40545 to your computer and use it in GitHub Desktop.
Save simonewebdesign/6eebc9a2a344f3bdba39b279b8f40545 to your computer and use it in GitHub Desktop.
Sum of positives in Haskell
positiveSum :: [Int] -> Int
positiveSum a =
let
positives = filter (>0) a
in
foldl (+) 0 positives
# …OR…
positiveSum :: [Int] -> Int
positiveSum a =
let
positives = filter (>0) a
in
sum positives
# …OR... pointfree style
positiveSum :: [Int] -> Int
positiveSum =
foldl (+) 0 . filter (>0)
# …OR just…
positiveSum :: [Int] -> Int
positiveSum =
sum . filter (>0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment