Created
November 28, 2010 21:54
-
-
Save wardbekker/719332 to your computer and use it in GitHub Desktop.
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
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)] |
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
module Main where | |
import Foo | |
main = savefile $ myfold foobarlist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pattern matching, file IO, a lambda, lists and tupels. Something for everybody ;-)