Skip to content

Instantly share code, notes, and snippets.

@wardbekker
Created November 28, 2010 21:54
Show Gist options
  • Save wardbekker/719332 to your computer and use it in GitHub Desktop.
Save wardbekker/719332 to your computer and use it in GitHub Desktop.
module Foo where
import System.IO
-- define fold
myfold :: (Num b) => [(t, b)] -> b
myfold ((t,b):xs) = foldr (\(t,b) x -> x + b) 0 ((t,b):xs)
-- define writing results to file
savefile :: (Num b) => b -> IO()
savefile b = do
let result = show b
writeFile "fold_result.txt" ("fold=" ++ result)
-- input data
foobarlist = [("foo", 1), ("bar", 2), ("foo", 4), ("bar", -1), ("bar", -1)]
module Main where
import Foo
main = savefile $ myfold foobarlist
@wardbekker
Copy link
Author

Pattern matching, file IO, a lambda, lists and tupels. Something for everybody ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment