[Haskell-cafe] Int vs Integer?

Daniel Carrera dcarrera at digitaldistribution.com
Thu May 5 04:37:09 EDT 2005


Cale Gibbard wrote:
> Int is the type of machine integers, with guaranteed range at least
> -2^29 to 2^29 - 1, while Integer is arbitrary precision integers, with
> range as large as you have memory for.

Alright, that was my guess (though I had no idea which was which).

> I expect you'll replace ints with a more interesting list, as ints !! i is
> currently equal to i.

Yeah. I'm actually writing the PRNG component of RC4. I figured that 
would be a simple yet interesting problem to get started with Haskell. 
But I wanted to show the most minimal function I could that still 
illustrates the problem I have.


> If you need to coerce something of integral (Int, Integer) type to any
> numeric type, use fromIntegral.

Okay, I just guessed that I should use it like this:

      j = ints !! fromIntegral( i )

That seems to work, so I'll go with it.

Thanks!

Cheres,
Daniel.


More information about the Haskell-Cafe mailing list