Prelude function suggestions

Henning Thielemann iakd0 at clusterf.urz.uni-halle.de
Fri Jul 30 04:28:18 EDT 2004


On Thu, 29 Jul 2004, Tomasz Zielonka wrote:

> On Thu, Jul 29, 2004 at 06:29:52PM +0200, Henning Thielemann wrote:
> > Say, you have some stop condition that you want to use in connection with
> > unfoldr: 
> > 
> > unfoldr (\n -> toMaybe (n<10) (n,n+1)) 0
> 
> How about using MonadPlus instance for Maybe? It seems a bit clearer to
> me.
> 
>     unfoldr (\n -> guard (n<10) >> return (n,n+1)) 0

Ok, nice. Though then again I think about falling back to
  unfoldr (\n -> if n<10 then Just (n,n+1) else Nothing) 0

I just use toMaybe as common abbreviation. If no one needs it, forget it.
:-)




More information about the Libraries mailing list