Typing f.e.d.

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Tue Feb 13 02:15:47 EST 2001


Mon, 12 Feb 2001 15:49:45 -0700, Alastair Reid <reid at cs.utah.edu> pisze:

> 1) Trying to support a complex language like Java in the same design
> (or in any design, really)

Java support has no impact on C support: you can ignore it if you like.
The design as is is quite language-independent (and proposed to be yet
more independent, by moving some C-specific bits to a better place).

> 2) Moving library specs, etc. out of the individual ffi decls.

Why would you want to require to repeat the same words with every
declaration?!

> >    * Pointers to code and data need not have the same size.
> 
> I understand this argument though I'm not sure which architectures
> this applies to.

AFAIK IA64. And MS-DOS.

> How often do you have to create two Haskell types which really
> ought to be just one type just so that you can use the overloading?

I can't remember I've ever done this.

> Is pointer arithmetic on Ptr's useful?  (It's obviously useful for
> arrays but can you use it (safely and portably) to access fields
> of structs or do you have to add an explicit byte count to get
> predictable/safe results.)

For structs the type of the pointer to the struct plays no role.
You can use hsc2hs and write
    uid <- (#peek struct stat, st_uid) ptr
Otherwise you have to use a C wrappper.

> What's the preferred way to represent an opaque C data type which
> happens to be a pointer?

I prefer this:
    data FooTag = FooTag
    -- IMHO should be: data FooTag, but this is not supported.
    
    type Foo = Ptr FooTag
    -- Sometimes ForeignPtr, sometimes both.

When the pointer points to known data with unknown representation
(data which can be extrated and used to recreate such object),
instead of FooTag you can represent the data as a Haskell type and
write appropriate Storable instances. It has not happened to me but
I guess that some glib types (gstring?) could be treated that way.

Sometimes I use just Ptr (), when it's used once or twice locally.

> What libraries is the evolving design being tried out on (I know
> about your OpenGL library).

In QForeign <http://www.sourceforge.net/projects/qforeign/> you can
see it applied to bzip2, curses, db3 (incomplete), glob (function),
libgr, pcap, readline, zlib, and a bunch of functions mostly from libc
(tests/Varia.hsc).

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTÊPCZA
QRCZAK





More information about the FFI mailing list