[Haskell] sizeFM type
dgroves at ccwebster.net
Mon Apr 26 16:55:23 EDT 2004
On Mon, 26 Apr 2004 21:21:09 +0200, Remi Turk <rturk at science.uva.nl> wrote:
> On Mon, Apr 26, 2004 at 08:58:53PM +0200, Wolfgang Jeltsch wrote:
>> Am Montag, 26. April 2004 20:45 schrieb Don Groves:
>> > 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...
>> 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.
> indeed: (Using GHC "unboxed types" with -fglasgow-exts)
> data Integer = S# Int# | J# Int# ByteArray#
> Prelude GHC.Exts> case 2^20::Integer of S# i -> S# i
> Prelude GHC.Exts> case 2^200::Integer of S# i -> S# i
> *** Exception: <interactive>:1: Non-exhaustive patterns in case
Wolfgang and Remi,
Thanks to you both for the explanation. Yes, the GHC Integer
type does what I was referring to and clearly anything done at
runtime will slow execution.
For future reference, if I know an integer will never exceed
an Int, I should type it that way to optimize speed; but using
Integer will optimize safety - right?
More information about the Haskell