[Haskell] sizeFM type
rturk at science.uva.nl
Mon Apr 26 22:21:09 EDT 2004
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
Have a nice day,
Nobody can be exactly like me. Even I have trouble doing it.
More information about the Haskell