
26 Jun
2011
26 Jun
'11
9:27 a.m.
On Jun 26, 2011, at 8:25 AM, Heinrich Apfelmus wrote:
What about the combinator
withFile :: FilePath -> (String -> a) -> IO a withFile name f = bracket (openFile name ReadMode) hClose $ \h -> evaluate . f =<< hGetContents h
? It gives you the same thing as Iteratees - a way to apply a function to the contents of a file - without the need to rewrite all the existing list functions like map , lines , words , and so on.
How would you, for instance, implement the program for counting all the words in a list of files that Oleg describes in his message?
Nested calls to withFile would require too many open handles. ____________________ David Place Owner, Panpipes Ho! LLC http://panpipesho.com d@vidplace.com