
On 16 Feb 2008, at 5:04 PM, Donn Cave wrote:
On Feb 16, 2008, at 3:46 PM, Philippa Cowderoy wrote:
On Sat, 16 Feb 2008, Alan Carter wrote:
I'm a Haskell newbie, and this post began as a scream for help.
Extremely understandable - to be blunt, I don't really feel that Haskell is ready as a general-purpose production environment unless users are willing to invest considerably more than usual. Not only is it not as "batteries included" as one might like, sometimes it's necessary to build your own batteries!
Ironically, the simple task of reading a file is more work than I expect precisely because I don't want to bother to handle exceptions. I mean, in some applications it's perfectly OK to let an exception go to the top.
But in Haskell, you cannot read a file line by line without writing an exception handler, because end of file is an exception! as if a file does not normally have an end where the authors of these library functions came from?
I agree 100%; to make life tolerable around Haskell I/O, I usually end up binding the moral equivalent of tryJust (\ exc -> case exc of IOException e | isEOFError e -> return () _ -> Nothing) $ getLine somewhere at top level and then calling that where it's needed.
For the author of the original post ... can't make out what you actually found and tried, so you should know about "catch" in the Prelude, the basic exception handler.
Also, you might need to know that bracket nests in various ways: bracket openFile hClose $ bracket readLine cleanUpLine $ proceed There's also finally, for when the first argument to bracket is ommitted, and (>>) for when the second argument is :) jcc