On 9/27/07, PR Stanley <[EMAIL PROTECTED]> wrote: > Hi > intToBin :: Int -> [Int] > intToBin 1 = [1] > intToBin n = (intToBin (n`div`2)) ++ [n `mod` 2] > > binToInt :: [Integer] -> Integer > binToInt [] = 0 > binToInt (x:xs) = (x*2^(length xs)) + (binToInt xs) > Any comments and/or criticisms on the above definitions would be appreciated. > Thanks , Paul
IntToBin diverges for inputs <= 0. You could get 0 "for free" with intToBin :: Int -> [Int] intToBin 0 = [] intToBin n = (intToBin (n`div`2)) ++ [n `mod` 2] And why not use [Bool] for the "Bin" type? Or data Bin = Zero | One Regards, Chris _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe