
I think Integer is prefered in Haskell. I mean normally, I should use
it in my code. So following my example, why cannot CPid be treated as
Integer. Only when it needs to be transfered to C or whatsoever, we
convert it to Long or whatsoever. So we have a unified type system,
not a bunch of types I need to convert, convert, convert.
And, let say using Integer for pid is insane. Then if I do not convert
it into Integer, when serialised, I have to point out with
Word32/Word64, which is definitely bad.
On Tue, Jun 30, 2009 at 11:01 AM, Ahn, Ki Yung
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 sane.
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
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- 竹密岂妨流水过 山高哪阻野云飞