[Haskell] Re: sizeFM type

Donald Bruce Stewart dons at cse.unsw.edu.au
Tue Apr 27 16:09:49 EDT 2004


mechvel:
> On Mon, Apr 26, 2004 at 04:06:22PM +0100, Philippa Cowderoy wrote:
> > On Mon, 26 Apr 2004, Serge D. Mechveliani wrote:
> > 
> > > Alexander is right.
> > >
> > > Also as  Integer  has more sense than  Int,
> > >
> > 
> > To ask a silly question, is Int defined as 32 bits or is it defined in a
> > similar vein to C's int?

Well, you can all look this up, at least in GHC's implementation:

  $fptools/libraries/base/GHC/Base.lhs:
          data Int = I# Int#
          -- ^A fixed-precision integer type with at least the range @[-2^29
          -- .. 2^29-1]@.  The exact range for a given implementation can be
          -- determined by using 'minBound' and 'maxBound' from the 'Bounded'
          -- class.

  $fptools/ghc/compiler/prelude/primops.txt.pp:        
    section "The word size story."
            {Haskell98 specifies that signed integers (type {\tt Int})
             must contain at least 30 bits. GHC always implements {\tt
             Int} using the primitive type {\tt Int\#}, whose size equals
             the {\tt MachDeps.h} constant {\tt WORD\_SIZE\_IN\_BITS}.
             This is normally set based on the {\tt config.h} parameter
             {\tt SIZEOF\_HSWORD}, i.e., 32 bits on 32-bit machines, 64
             bits on 64-bit machines.  However, it can also be explicitly
             set to a smaller number, e.g., 31 bits, to allow the
             possibility of using tag bits. Currently GHC itself has only
             32-bit and 64-bit variants, but 30 or 31-bit code can be
             exported as an external core file for use in other back ends.
            
            ...

            #if WORD_SIZE_IN_BITS < 32 
            #define INT32 Int32#
            #define WORD32 Word32#
            #else
            #define INT32 Int#
            #define WORD32 Word#
            #endif

            #if WORD_SIZE_IN_BITS < 64
            #define INT64 Int64#
            #define WORD64 Word64#
            #else
            #define INT64 Int#
            #define WORD64 Word#
            #endif

-- Don


More information about the Haskell mailing list