[Haskell] sizeFM type

Wolfgang Jeltsch wolfgang at jeltsch.net
Mon Apr 26 21:58:53 EDT 2004

Am Montag, 26. April 2004 20:45 schrieb Don Groves:
> [...]

> Hello, Haskell newbie here.
> Some languages handle the Int/Integer question automatically,
> determined by the size of the integer in question.  Int is used
> until the integer excedes what the underlying architecture can
> handle, then the switch is made to Integer (bignum).  Is this
> something that could be handled similarly by the Haskell compiler
> without violating anything?  Just thinking out loud...
> --
> Don Groves

Hello Don,

strictly speaking, you cannot choose between Int or Integer depending on the 
actual value of your number because the type of an expression has to be known 
at compile time while the exact value is mostly known only at runtime.

But you can have a type which uses a "small int" representation for small 
numbers and a "big int" representation for big numbers.  This is probably 
what you mean, and this is AFAIK exactly what at least GHC's Integer does.  
So GHC's Integer uses a fast representation for small numbers.  But a program 
still needs time for testing if a given Integer is represented the "small" or 
the "big" way, it needs time for testing, if a calculation results in a 
number representable by the "small" representation etc.  So Integer will 
always be a bit slower than Int.


More information about the Haskell mailing list