Last active
June 16, 2016 12:13
-
-
Save simonewebdesign/6eebc9a2a344f3bdba39b279b8f40545 to your computer and use it in GitHub Desktop.
Sum of positives in Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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