As part of a larger program I have created the following functions to convert a list of bits into the integer represents, also to simplify things the order of the bits is reversed [1,1,0,1] represents 1011 (or 13). At the moment the frombin function below works fine.
type Bit = Int
frombin :: [Bit] -> Int
frombin xs = sum (tonum xs)
tonum :: [Bit] -> [Bit]
tonum [] = []
tonum (n:ns) = (n:(tonum (map (*2) ns)))
However why when I try the function below does it not work in Hugs?
frombin :: [Bit] -> Int
frombin [] = 0
frombin (n:ns) = sum (n:( frombin (map (*2) ns)))
Is this surely not just a combination of the two?
Any help would be much appreciated
Thanks,
Rob