FFI survey 
Author Message
 FFI survey

I'm currently writing a survey about FFI (and language extensions at
all) for various high level languages. I don't know ML or Haskell that
much, I come from lisp and c.
maybe someone could add some info, on more languages

http://www.*-*-*.com/ #haskell_ffi

Haskell extensions [new]

Haskell is a polymorphicly typed, lazy, purely functional language,
similar to the ML kind, based on the lambda calculus. I seem to like it
a lot, compared to ML which is a strict, not lazy, functional language.
Both types of functional language families are very strong in functional
interfaces and have a more C like syntax, so FFI's appear to fit very
natural into the language.
<p>

Haskell provides several rich extension possibilities: A FFI called
the "Glasgow's New Foreign Function Interface", an automatic wrapper
generator called C-&gt;Haskell, a IDL compiler called HaskellDirect,
an ActiveX server and client library called ActiveHaskell.<p>

C-&gt;Haskell was developed for the GTK binding. It is a C source parser
which works pretty well for an automatic binding generator.<p>

The FFI which comes with Hugs/GHC is a "primitive" (KISS) one.<p>
<xmp>
'foreign' 'import' [callconv] [ext_fun] ['unsafe'] varid '::' prim_type
</xmp>

<blockquote>
A foreign import declaration is only allowed as a toplevel
declaration. It consists of two parts, one giving the Haskell type
(prim type), Haskell name (varid) and a ag indicating whether the
primitive is unsafe, the other giving details of the name of the
external function (ext fun) and its calling interface (callconv.)
Giving a Haskell name and type to an external entry point is clearly
an unsafe thing to do, as the external name will in most cases be
untyped. The onus is on the programmer using foreign import to ensure
that the Haskell type given correctly maps on to the type of the
external function.</blockquote>

The Chalmers Haskell CCall library is even more primitive, but
different.<p>
<xmp>
ccallCU :: CPointer -> [CUnion] -> CUnion -> IO CUnion
ccallCV :: (CValue a) => CPointer -> [CUnion] -> IO a
...
</xmp>

<p>Links:
<ul>
  <li>Haskell <a href=" http://www.*-*-*.com/ ;>[home]</a>,
  <li>Glasgow's New Foreign Function Interface (FFI)
<a
href=" http://www.*-*-*.com/ ;>[paper
in ps]</a>,
  <li>C-&gt;Haskell <a
href=" http://www.*-*-*.com/ ~chak/haskell/c2hs/">[www]</a>,
  <li>HaskellDirect <a
href=" http://www.*-*-*.com/ ;>[www]</a>,
  <li>ActiveHaskell <a
href=" http://www.*-*-*.com/ ;>[www]</a>,
  <li>Chalmers Haskell CCall library <a
href=" http://www.*-*-*.com/ ~augustss/hbc/hbc_library.html">[www]</a>
</ul>    

ML: Extensions for the ML Family [new]

ML is a standard strict functional language. It is widely used in CS
introduction courses. Here are pointers to the various implementations
of this standard and other sites relating to ML.

<snipped generic links>

ML implementations have various FFI's. Some of them have papers and
references online:
<ul>
  <li>SML/NJ-C foreign function interface:
      <A
HREF=" http://www.*-*-*.com/ ;>[ref]</A>
  <li>Moscow ML DynLib FFI:
      <A
HREF=" http://www.*-*-*.com/ ~sestoft/manual/node10.html">[ref]</A>
  <li>ML Kit FFI:
      <A
HREF=" http://www.*-*-*.com/ ;>[desc]</A>
  <li>MLton FFI:
      <A
HREF=" http://www.*-*-*.com/ ;>[ref]</A>
  <li>MLj is a implementation in Java which supports a Java interface:
      <a href=" http://www.*-*-*.com/ ~mlj/doc/index.html">[www]</a>
  <li>Objective CAML C calling interface:
      <a
href=" http://www.*-*-*.com/ ;>[www]</A>
  <li>CAML Light C calling interface: (similar to OCAML)
      <a
href=" http://www.*-*-*.com/ ;>[www]</A>
  <li>Opal is another functional language with a foreign language
interface:
      <a href=" http://www.*-*-*.com/ ~opal/">[home]</a>,
      <a
href=" http://www.*-*-*.com/ ;>[ps:
page 58]</a>.
        It compiles to C, calls foreign extensions "hand-coding",
      and says "better don't do that".
  <li>...    
</ul>

--
Reini Urban
http://www.*-*-*.com/



Thu, 15 Aug 2002 03:00:00 GMT  
 FFI survey
Is it okay to say the following in this context?

<ffis>
Erlang is just another great high-level functional language that
recently went open source. Is was developed by Ericsson, Sweden. It
is pretty large and quite "over-featured", just see the [doc mainpage]

The FFI is not dynamic (to my limited knowledge), there's just a library
to help in C code extensions for argument translation and
such. But there are also two Java interface libraries and a IDL parsing
interface, which allows dynamic and high-level extensions.
Mnesia Session e.g. is a foreign language interface to the internal
Mnesia Database interfaced to via IDL. [sample]

http://www.erlang.org/documentation/lib/mnesia_session-1.1.3/doc/html...

Links:
[home], [c interface].

http://www.erlang.org/documentation/lib/erl_interface-3.2/doc/index.html
</ffis>

I also added dylan, Smalltalk, forth, minotaur and poplog now.

Quote:

>I'm currently writing a survey about FFI (and language extensions at
>all) for various high level languages. I don't know ML or Haskell that
>much, I come from lisp and c.
>maybe someone could add some info, on more languages

>http://xarch.tu-graz.ac.at/autocad/lisp/ffis.html#haskell_ffi

--                                        
Reini


Sat, 17 Aug 2002 03:00:00 GMT  
 FFI survey

  Reini> Is it okay to say the following in this context?  <ffis>
  Reini> Erlang is just another great high-level functional language
  Reini> that recently went open source. Is was developed by Ericsson,
  Reini> Sweden. It is pretty large and quite "over-featured", just
  Reini> see the [doc mainpage]

You need to distinguish between the language Erlang and the
middleware platform OTP.

OTP is pretty large, but it was designed to support development
of very complex high-availability applications.

The documentation you refer to include things like a DBMS, SNMP
CORBA, a HTTP server, and various other useful components. They
are not part of the language. Also on the documentation page are
course materials and various tutorials, as well as some published
papers.

I'd say Erlang is a reasonably small language, if you read
the (relatively wordy) specification:

http://www.erlang.org/download/erl_spec47.ps.gz

 Lexial structure: 11 pages
 Types and terms : 14 pages
 Arithmetics     : 12 pages
 Expressions & Evaluation : 49 pages
 Processes and Concurrency: 14 pages
 Distribution: 10 pages
 Ports: 10 pages
 Built-In Functions: 45 pages

Specifically which language features are you refering to when you
call Erlang "over-featured"?

  Reini> The FFI is not dynamic (to my limited knowledge), there's
  Reini> just a library to help in C code extensions for argument
  Reini> translation and such. But there are also two Java interface
  Reini> libraries and a IDL parsing interface, which allows dynamic
  Reini> and high-level extensions.  Mnesia Session e.g. is a foreign
  Reini> language interface to the internal Mnesia Database interfaced
  Reini> to via IDL. [sample]

Erlang doesn't really have an FFI, apart from linked-in drivers.
(given your definition that the foreign functions should execute
in the same process space.)

Using a linked-in driver, you can load a C routine as a shared object.
All external interfaces, including linked-in drivers, are instantiated
as "ports", which appear to the Erlang programmer essentially as a
process, with which you can communicate via message passing.
Except for linked-in drivers, all external programs execute as
separate processes outside the Erlang VM.

/Uffe
--
Ulf Wiger, Chief Designer AXD 301
Ericsson Telecom AB                          tfn: +46  8 719 81 95
Varuv?gen 9, ?lvsj?                          mob: +46 70 519 81 95
S-126 25 Stockholm, Sweden                   fax: +46  8 719 43 44



Sun, 18 Aug 2002 03:00:00 GMT  
 FFI survey

Quote:


>  Reini> Is it okay to say the following in this context?  <ffis>
>  Reini> Erlang is just another great high-level functional language
>  Reini> that recently went open source. Is was developed by Ericsson,
>  Reini> Sweden. It is pretty large and quite "over-featured", just
>  Reini> see the [doc mainpage]

>You need to distinguish between the language Erlang and the
>middleware platform OTP.

Oops. I really wanted to say:
"Erlang is just another great high-level functional language
implementation that recently went open source."

language vs library issues are always confusing. FFI's are always
library issues which needs to fit (more or less) into the underlying
language framework. same languages can deal with that worse (e.g. perl,
Visual Basic) and some better (lisps and the other functional languages)

Quote:
>I'd say Erlang is a reasonably small language, if you read
>the (relatively wordy) specification:
>Specifically which language features are you refering to when you
>call Erlang "over-featured"?

Sorry, the library is over-featured. :)
of course not really, just in comparison to other packages.
I am just overwhelmed.

Quote:
>  Reini> The FFI is not dynamic (to my limited knowledge), there's
>  Reini> just a library to help in C code extensions for argument
>  Reini> translation and such. But there are also two Java interface
>  Reini> libraries and a IDL parsing interface, which allows dynamic
>  Reini> and high-level extensions.  Mnesia Session e.g. is a foreign
>  Reini> language interface to the internal Mnesia Database interfaced
>  Reini> to via IDL. [sample]

>Erlang doesn't really have an FFI, apart from linked-in drivers.
>(given your definition that the foreign functions should execute
>in the same process space.)

>Using a linked-in driver, you can load a C routine as a shared object.
>All external interfaces, including linked-in drivers, are instantiated
>as "ports", which appear to the Erlang programmer essentially as a
>process, with which you can communicate via message passing.
>Except for linked-in drivers, all external programs execute as
>separate processes outside the Erlang VM.

so it's similar to emacs, which mainly uses comint for external
communication. arbitrary ports are of course better than just
STDIN/STDOUT with all the shell problems (portable string quoting,
wildcard expansion, ...)
BTW, I do like the simplicity of this design. this is the world unix was

built upon.
it also accomplishes transparence of locality.

thanks ulf.
--
Reini Urban
http://xarch.tu-graz.ac.at/autocad/lisp/ffis.html



Sun, 18 Aug 2002 03:00:00 GMT  
 FFI survey
: I'm currently writing a survey about FFI (and language extensions at
: all) for various high level languages. I don't know ML or Haskell that
: much, I come from lisp and c.
: maybe someone could add some info, on more languages

You might want to add something about the extension mechanism
for MzScheme, http://www.cs.rice.edu/CS/PLT/packages/mzscheme/.
MzScheme allows C/C++ extensions to be loaded as dynamic
libraries.

-- Paul

 ----------------------------------------------------------------
| Paul Steckler              |     Rice University PLT           |

| Tel:  713/348-3814         |     http://www.cs.rice.edu/~steck |
| FAX:  713/348-5930         |     *** Ad astra per hackera ***  |
 ----------------------------------------------------------------



Tue, 20 Aug 2002 03:00:00 GMT  
 FFI survey


  Paul> You might want to add something about the extension mechanism
  Paul> for MzScheme, http://www.cs.rice.edu/CS/PLT/packages/mzscheme/.
  Paul> MzScheme allows C/C++ extensions to be loaded as dynamic
  Paul> libraries.

Gambit, Bigloo and STk (and probably several other schemes) all allow
dynamic loading of extensions on platforms which allow dynamic loading
(e.g. Linux).  They all have FFI's.  I've only used Gambit's and it is
very nice.  Interfacing to C routines under Gambit is trivial.

Brian



Wed, 21 Aug 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. FFI survey for smalltalk

2. FFI survey

3. Informal survey of Scheme library/FFI use

4. portable FFI representation

5. Calling Haskell function from C (FFI) causes seg-fault (GHC,linux)

6. Monads, GreenCard and ffi

7. Fun-O Win32 FFI Question

8. c-ffi question involving c-struct

9. C FFI question

10. FFI question #2: Getting the address of a C function

11. FFI question: Setting array elements

12. FFI questions

 

 
Powered by phpBB® Forum Software