On 15-Oct-1998, Hans Aberg <[EMAIL PROTECTED]> wrote:
> At 17:25 +1000 98/10/15, David Glen JEFFERY wrote:
> >Does something like this exist? FWIW, I'm using Hugs 1.4
>
> I gather that "FWIW" is yet another SSMA; what does it mean?
For What It's Worth. Okay... I'll bite. What's SSMA?
Anyhow, for those who are interested in my original question about a
non-aborting read, a colleague of mine provided this:
------------------------------------------------------------
-- Author: Bernie Pope ([EMAIL PROTECTED])
module MyRead (myread) where
myread :: Read a => String -> Maybe a
myread s = case [x | (x,t) <- reads s, ("","") <- lex t] of
[x] -> Just x
[] -> Nothing
_ -> Nothing
------------------------------------------------------------
Also, Noel Winstanley mailed me directly and suggested that I use
unsafePerformIO and catch the exception:
safe_read s = unsafePerformIO $ (map Just . readIO $ s) `catch`
(\_ -> return Nothing)
That's also not a bad idea, but I think that "myread" above is simpler.
Perhaps something like this should be added to the standard library.(?)
dgj
--
David Jeffery ([EMAIL PROTECTED]) | Marge: Did you just call everyone "chicken"?
PhD student, | Homer: Noooo. I swear on this Bible!
Department of Computer Science | Marge: That's not a Bible; that's a book of
University of Melbourne | carpet samples!
Australia | Homer: Ooooh... Fuzzy.