Re: [Haskell-cafe] golf, predicate check function for MonadPlus (was Re: How to read safely?)

2009-07-06 Thread Dan Doel
On Thursday 02 July 2009 6:36:09 am Jon Fairbairn wrote: check :: (MonadPlus m) = (a - Bool) - a - m a check p a | p a = return a | otherwise = mzero I tried Hoogling for a function like check, but couldn't find it. Surely there's one in a library somewhere? It looks useful to me.

Re: [Haskell-cafe] golf, predicate check function for MonadPlus (was Re: How to read safely?)

2009-07-06 Thread Antoine Latter
On Mon, Jul 6, 2009 at 8:49 PM, Dan Doeldan.d...@gmail.com wrote: I've often noticed the need for a similar function in conjunction with unfoldr:  -- This is overly general for unfoldr, but it lines up with check  stopAt :: (MonadPlus m) = (a - Bool) - (a - b) - a - m b  stopAt p f x    |

[Haskell-cafe] golf, predicate check function for MonadPlus (was Re: How to read safely?)

2009-07-02 Thread Jon Fairbairn
Dan Doel dan.d...@gmail.com writes: There was talk of adding a readMaybe a while ago, but apparently it never happened. As it is, you can use reads, read s becomes: case reads s of [(a, rest)] | all isSpace rest - code using a _ - error case

Re: [Haskell-cafe] golf, predicate check function for MonadPlus (was Re: How to read safely?)

2009-07-02 Thread Alexander Dunlap
On Thu, Jul 2, 2009 at 3:36 AM, Jon Fairbairnjon.fairba...@cl.cam.ac.uk wrote: Dan Doel dan.d...@gmail.com writes: There was talk of adding a readMaybe a while ago, but apparently it never happened. As it is, you can use reads, read s becomes:     case reads s of       [(a, rest)] | all