Previous: Java data passing conventions, Up: Data passing conventions   [Contents]


14.3.4 Erlang data passing conventions

The Mercury types int, float and char are mapped to Erlang integers, floats and integers respectively. A Mercury string is represented by an Erlang binary, not by a list of integers.

Mercury variables whose type is a Mercury discriminated union type will be passed as an Erlang tuple with the first element of the tuple being an Erlang atom named after the Mercury data constructor. For example, values of the type:

:- type maybe_int
    --->    yes(int)
    ;       no.

would be represented in Erlang as ‘{yes, integer}’ and ‘{no}’.

Mercury variables whose type is a Mercury equivalence type will be passed as the representation of the right hand side of the equivalence type.

This mapping is subject to change and you should try to avoid writing code that relies heavily upon a particular representation of Mercury terms.

Arguments of dummy types, e.g. ‘io.state’, are represented by the atom ‘false’ when necessary. They are not passed to and from calls to monomorphic procedures.

Mercury arguments declared with input modes are passed by value to the corresponding Erlang function.

The result of an Erlang function depends on the determinism of the Mercury procedure that it was derived from. Procedures which succeed exactly once and have a single output variable return the single value directly. Procedures which succeed exactly once and have zero or two or more output variables return a tuple of those output variables in order.

Procedures which are semideterministic return, on success, a tuple of the variables with output modes (including when the number of output variables is one). On failure they return the Erlang atom ‘fail’.

Procedures which are nondeterministic take as a final argument a success continuation. This is an function which has an input variable for each variable of the Mercury procedure with an output mode. For each solution, the success continuation is called with the values of those output variables. When there are no more solutions the Erlang function returns with an undefined value.


Previous: Java data passing conventions, Up: Data passing conventions   [Contents]