Next: , Previous: , Up: Interfacing with Erlang   [Contents]


14.10.4.3 Using pragma foreign_export for Erlang

A ‘pragma foreign_export’ declaration for Erlang has the form:

:- pragma foreign_export("Erlang", MercuryMode, "Erlang_Name").

For example,

:- pragma foreign_export("Erlang", foo(in, in, out), "foo").

The type signature of the Erlang interface to a Mercury procedure is described in Erlang data passing conventions.

Calling polymorphically typed Mercury procedures from Erlang is a little bit more difficult than calling ordinary (monomorphically typed) Mercury procedures. The simplest method is to just create monomorphic forwarding procedures that call the polymorphic procedures, and export them, rather than exporting the polymorphic procedures.

If you do export a polymorphically typed Mercury procedure, the compiler will prepend one ‘type_info’ argument to the parameter list of the Erlang interface function for each distinct type variable in the Mercury procedure’s type signature. The caller must arrange to pass in appropriate ‘type_info’ values corresponding to the types of the other arguments passed. These ‘type_info’ arguments can be obtained using the Mercury ‘type_of’ function in the Mercury standard library module ‘type_desc’.