On Mon, 2009-01-12 at 21:48 +0000, Robin Green wrote:
> > > convert b = unfoldr (\n -> if n > 0 then Just (n `mod` b, n `div`
> > > b) else Nothing)
> > 
> > I have the nice function 'toMaybe' which simplifies this to:
> >    unfoldr (\n -> toMaybe (n>0) (n `mod` b, n `div` b))
> 
> I would use the more general idiom:
> 
>      unfoldr (\n -> guard (n > 0) >> return (n `mod` b, n `div` b))

I have the equivalent in my ‘useful functions’:

> ifM p x = if p then return x else mzero


Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to