
13 Jan
2009
13 Jan
'09
1:13 p.m.
Robin Green wrote:
On Mon, 12 Jan 2009 21:04:35 +0100 (CET) Henning Thielemann
wrote: On Mon, 12 Jan 2009, Andrew Coppin 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)
One of the wonderful things about Haskell is that almost any time anybody posts code, at least one person will think up an alternative but equivilent way of achieving the same goal - sometimes by radically different steps. Maybe we should have a name for this effect?