Next: , Previous: Calling foreign code from Mercury, Up: Foreign language interface   [Contents]

14.2 Calling Mercury from foreign code

Mercury procedures may be exported so that they can be called by code written in a foreign language.

A declaration of the form:

:- pragma foreign_export("Lang",
    Pred(Mode1, Mode2, …), "ForeignName").


:- pragma foreign_export("Lang",
    Func(Mode1, Mode2, …) = Mode,

exports a procedure for use by foreign language Lang. For each exported procedure, the Mercury implementation will create an interface to the named Mercury procedure in the foreign language using the name ForeignName. The form of this interface is dependent upon the specified foreign language. For further details see the language specific information below.

It is an error to export a Mercury procedure that has a determinism of multi or nondet.