[Haskell-cafe] Re: Wondering about c type in haskell.

Ahn, Ki Yung kyagrd at gmail.com
Mon Jun 29 23:01:33 EDT 2009

Magicloud Magiclouds 쓴 글:
> Hi,
>   There are times, when we need to make some system calls, or call C
> library. So we have to deal with C data types.
>   For example, CPid, which is an integer, actually. So we can do
> "fromIntegral pid". Then why do not we define "type CPid = Integer",
> and convert Haskell Integer with C Int internally. So the "user" does
> not have to care about the type convert (everywhere, which is ugly).
> And, specially, when doing something like serialisation, for Haskell
> Integer, the user does not have to do things with precision. But for
> CPid, without the fromIntegral, we have to specify its precision,
> well, on different machine/OS, the precision may not be the same.

Integer is not a fixed length chunk of bits.  It can be arbitrarily 
large as long as there is memory left in the system.  It's theoretically 
more clean being close to a mathematical definition of integers, but 
internally a complicated beast.  So defining CPid as Integer is just not 

In addition, we cannot use Int either.  Int is not a 32 bit or 64 bit 
word.  The Haskell 98 standard does not require that, and in most 
implementations it is 2^31 singed bits using one bit as a mark to 
distinguish pointers from values for garbage collection purposes. 
(OCaml int types are like that too.)

I hope this gives enough explanation.

   Ahn, Ki Yung

More information about the Haskell-Cafe mailing list