[Haskell-begin] Maximum of a List?

Niels Aan de Brugh nielsadb at gmail.com
Sun Jul 27 07:53:00 EDT 2008


Steve Klabnik wrote:
> f :: Int -> Int -> Int
> f acc x
>     | x == 1 = acc
>         | even x = f (acc + 1) (x `div` 2)
>         | otherwise = f (acc + 1) (3 * x + 1)
One more remark: you're using Ints. This type is limited to 
[-2^31..2^31]. Maybe you should use Integers, or only specify that the 
in- and output should be numeric, or perhaps even omit the type 
annotation altogether.

Try running: f 1 113383
(with Int and Integer/no type annotation)

Niels


More information about the Beginners mailing list