[Haskell-cafe] Wondering about c type in haskell.
John Meacham
john at repetae.net
Tue Jun 30 05:32:26 EDT 2009
On Tue, Jun 30, 2009 at 10:01:48AM +0800, Magicloud Magiclouds wrote:
> 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.
Because we need to actually convey to the haskell implementation what
the proper calling conventions for the function are, if we used type
synonyms, we would have no way to know whether the type passed is a
long, short, or whatever. We need to use real types to tell the FFI spec
how to bind to the external function properly.
John
--
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/
More information about the Haskell-Cafe
mailing list