[m-dev.] `pred' and `mode' declarations and the module system
Julien Fischer
jfischer at opturion.com
Mon Jan 11 15:58:01 AEDT 2016
Hi,
The reference manual does not currently define an aspect of the interaction
between `pred' (or `func`) declarations, `mode' declarations and the module
system: are all the modes of an exported predicate required to be exported
themselves? Currently, the compiler allows the following:
:- module example.
:- interface.
:- pred foo(int, int).
:- mode foo(in, out) is semidet.
:- implementation.
:- mode foo(out, in) is semidet.
...
And indeed, it currently allows you to export a predicate without exporting any
of the modes at all:
:- module example2
:- interface.
:- pred foo(int, int).
:- implementation.
:- mode foo(in, out) is semidet.
:- mode foo(out, in) is semidet.
...
(Regardless of the what the intended behaviour is, the second example should at
least elicit a warning.)
Another issue related to `pred' and `mode' declarations is that the reference
manual says that if "a predicate or function has only one mode, the ‘pred’ and
‘mode’ declaration can be combined" -- this implies that it should be an error
for a predicate to have both a predmode declaration and separate mode
declarations. The compiler currently accepts that situation without complaint
as well.
:- module example3.
:- interface.
:- pred foo(int::in, int::out) is semidet.
:- mode foo(out, in) is semidet.
:- implementation.
...
(Ditto, if the same thing occurs for type class method declarations.)
I suggest that we change the language definition to require that:
1. *all* mode declarations for an exported predicate or function must also
be exported.
2. be explicit about the fact that mixing predmode declarations with separate
mode declarations is an error.
(And make the implementation conform to that.)
Julien.
More information about the developers
mailing list