Skip to content

Instantly share code, notes, and snippets.

@wavebeem
Created January 20, 2011 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wavebeem/787536 to your computer and use it in GitHub Desktop.
Save wavebeem/787536 to your computer and use it in GitHub Desktop.
3 different sum functions in Haskell
module Sum where
a [] = 0
a (x:xs) = x + a xs
b xs = b' 0 xs
where
b' q [] = q
b' q (x:xs) = b' (q + x) xs
c xs = foldl (+) 0 xs
list = [1 .. 100]
main =
do
print $ a list
print $ b list
print $ c list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment