[Haskell-beginners] Haskell Generic Function Question
Jeff Wheeler
jeff at nokrev.com
Thu May 28 13:18:22 EDT 2009
On Thu, 2009-05-28 at 13:05 -0400, Thomas Friedrich wrote:
> toDigit x = case f x of
> (0,b) -> [b]
> (a,b) -> toDigit a ++ [b]
>
> f = \x -> (x `quot` 10, x `mod` 10)
Your function f is almost the same as divMod in Prelude. Also, using a
lambda function seems odd; this is simpler:
> f x = (x `quot` 10, x `mod` 10)
Anyways, because that's essentially just divMod, toDigit can be
simplified thusly:
> toDigit x = case x `divMod` 10 of
> (0, b) -> [b]
> (a, b) -> toDigit a ++ [b]
Jeff Wheeler
More information about the Beginners
mailing list