Re: [Haskell-cafe] [Newbie question] -- Looping stdin until condition is met

2008-06-02 Thread Ryan Ingram
On 5/30/08, Martin Blais [EMAIL PROTECTED] wrote: 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

Re: [Haskell-cafe] [Newbie question] -- Looping stdin until condition is met

2008-06-02 Thread Neil Mitchell
Hi The best thing to do is bypass read and use 'reads' to define your own safe read. maybeRead :: Read a = String - Maybe a maybeRead s = case reads s of [(x, )] - Just x _ - Nothing Or just use the Safe package:

[Haskell-cafe] [Newbie question] -- Looping stdin until condition is met

2008-05-30 Thread Martin Blais
Allright, this is a definitely a newbie question. I'm learning Haskell and going through the exercises in the beautiful Hutton book, and one of them requires for me to write a loop that queries a line from the user (stdin), looping until the user enters a valid integer (at least that's how I want

Re: [Haskell-cafe] [Newbie question] -- Looping stdin until condition is met

2008-05-30 Thread Philip Weaver
On Fri, May 30, 2008 at 5:28 PM, Martin Blais [EMAIL PROTECTED] wrote: Allright, this is a definitely a newbie question. I'm learning Haskell and going through the exercises in the beautiful Hutton book, and one of them requires for me to write a loop that queries a line from the user

Re: [Haskell-cafe] [Newbie question] -- Looping stdin until condition is met

2008-05-30 Thread Don Stewart
blais: Allright, this is a definitely a newbie question. I'm learning Haskell and going through the exercises in the beautiful Hutton book, and one of them requires for me to write a loop that queries a line from the user (stdin), looping until the user enters a valid integer (at least

Re: [Haskell-cafe] [Newbie question] -- Looping stdin until condition is met

2008-05-30 Thread Don Stewart
philip.weaver: 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. Ah, that's a third option, sequence the effect using readIO, import System.IO import qualified Control.Exception as C

Re: [Haskell-cafe] [Newbie question] -- Looping stdin until condition is met

2008-05-30 Thread Martin Blais
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

Re: [Haskell-cafe] [Newbie question] -- Looping stdin until condition is met

2008-05-30 Thread Philip Weaver
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

Re: [Haskell-cafe] [Newbie question] -- Looping stdin until condition is met

2008-05-30 Thread Martin Blais
On Fri, 30 May 2008 17:19:54 -0700, Philip Weaver [EMAIL PROTECTED] said: 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