
13 Jan
2009
13 Jan
'09
4:28 p.m.
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