Function wows

Steffen Mazanek Steffen.Mazanek@UniBw-Muenchen.de
06 Mar 2003 02:02:23 +0000


Hello,

> frombin :: [Bit] -> Int
> 
> frombin [] = 0
> 
> frombin (n:ns) = sum (n:( frombin (map (*2) ns)))

frombin takes a list of Bits and returns an
Int, but (:) needs a list as its second argument.
Try something like

> frombin (n:ns) = n + 2*(frombin ns)

or

>frombin = foldr (\x y->x+2*y) 0

Ciao,
Steffen