[Haskell-cafe] unfoldr [ANN: HLint 1.2]

George Pollard porges at porg.es
Tue Jan 13 16:28:41 EST 2009


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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090114/ef0d9c48/attachment.bin


More information about the Haskell-Cafe mailing list