Haskell FFI 1.0 vs Haskell/Direct: influence? loss of abstraction level?

Hoehle, Joerg-Cyril Joerg-Cyril.Hoehle at t-systems.com
Thu Apr 25 05:25:58 EDT 2002


I've been busy with FFI design issues since 1995 (mostly Common Lisp).
I was very impressed by the article "H/Direct: A Binary Foreign Language Interface for Haskell" (ICFP'98). It got me in touch with IDL.

I'm quite surprised that the Haskell FFI 1.0 doesn't mention H/Direct or appears to take ideas from it. The H/Direct article says IIRC that it's the fruit of many years and iterations on FFI issues. I can confirm that by parallel experience in Lisp (OTOH, I can expand on low-level vs high-level FFI in a later email if you wish, esp. high-level failing to match some weird functions, but excellent 80-95% solutions).

I very much appreciated the elegant declaration of many functions, especially the size_is() indication for the length of an array. It maps well onto many "pass buffer and length" functions, e.g. gethostname(), zlib:compress().

I'm disappointed that I do not find such an elegant approach reflected in the Haskell 98 Foreign Function Interface 1.0 (I read release Candidate 1).

Therefore, I'd like to query the Haskell FFI mailing list for the reasons which may have lead to drop the very declarative approach of H/Direct in favour of the FFI 1.0, which to me, appears rather low-level (in contrast).

To make things more concrete and to show the influence of H/Direct, here is what I dream of for the CLISP, an implementation of Common Lisp. Only is_size() (and :guard) are missing. :language, :[in-]out parameters, arbitrarily complex structure definitions, :alloca (vs :malloc-free), 0-terminated arrays (c-array-max & c-array-ptr) and the declarative style of definition have been in CLISP since 1995.

(def-lib-call-out zlib-compress [eventually library]
  (:name "compress")
  (:arguments (dest (c-ptr (c-array uint8 is_size(destlen)))
                    :out :alloca)
              (destlen ulong :in-out :alloca)
              (source (c-ptr (c-array uint8 is_size(sourcelen))))
              (sourcelen ulong))
  (:return-type int)
  ;; -- only dereference :out parameters when condition on return code is met:
  (:guard #'zerop)
  (:language :stdc))

Thanks for shedding light on this topic,
	Jörg Höhle.
CLISP FFI documentation: http://clisp.cons.org/impnotes.html#dffi
zlib: http://www.gzip.org/zlib/manual.html
Feature Request: Searchable archives at haskell.org/pipermail :)

More information about the FFI mailing list