On Fri, May 30, 2008 at 5:14 PM, Martin Blais <[EMAIL PROTECTED]> wrote:
> On Fri, 30 May 2008 16:54:18 -0700, "Philip Weaver"
> <[EMAIL PROTECTED]> said:
>> > 1. How do I catch the exception that is raised from "read"?
>> >
>> I think you want readIO, which yields a computation in the IO monad,
>> so it can be caught.
>
> Holy schmoly, there it is, words of wisdom, written as clearly as can
> be, from the docs:
>
>  The readIO function is similar to read except that it signals parse
>  failure to the IO monad instead of terminating the program.
>
> I'll be prosternating on the floor towards my web browser for the next
> four hours.
> Thank you very much Philip.
>
> (And thank you Don for the verbose examples.)
>
>
>
>> > 2. Where do I find the appropriate information I need in
>> >   order to fix this? I'm probably just not searching in the
>> >   right place. (Yes, I've seen the GHC docs, and it doesn't
>> >   help, maybe I'm missing some background info.)
>> >
>> In this particular case, I am not sure where you'd find this
>> information.  It's not very intuitive to a beginner why "read" doesn't
>> work in this case.
>
> Dear Philip, could you point your virtual finger towards a
> reference/paper/book/any-bleeping-thing that would help this simple
> beginner understand why it doesn't work in this case? I'm trying to
> picture why a "read" function that terminates the program would be
> useful anywhere. In fact, any library function other than something like
> UNIX's "exit" or "kill" which terminates my program is not really
> welcome in any of my computer programs, but then again, I haven't yet
> been illuminated by the genie of pure functional languages.  A reference
> would be awesome.
>
Sorry, I wouldn't know where to point you, other than stating the
simple rule that you can't catch exceptions in pure code.  Others may
be able to enlighten you better.

By the way, the example that Dons gave may look more verbose, but
(when possible) it's a probably a better idea to capture failure in a
Maybe than in IO.  I gave you "readIO" because it fit in to the
exception handling that you were trying to do, and because you said
you didn't want anyone to tell you you were doing things wrong :).

>
>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to