[mercury-users] Higher order programming

Lee Naish lee at cs.mu.OZ.AU
Fri Apr 23 17:02:33 AEST 1999


In message <19990423151715.C13078 at mundook.cs.mu.OZ.AU>Fergus wrote:
>On 23-Apr-1999, Lee Naish <lee at cs.mu.OZ.AU> wrote:
>So I guess you're thinking of something like say
>
>	:- pred plus(int, int, int).
>	:- mode plus(in, in, out) is function.
>				% meaning the same as `is det',
>				% plus you are also allowed to use
>				% functional syntax for this mode
>	:- mode plus(out, in, in) is det.
>	:- mode plus(in, out, in) is det.

Yes, that kind of thing.  Alternatively, a function definition with
additional mode declarations to allow it to be used backwards etc, *but
only with the relational syntax*. eg

:- func plus(int, int) = int.  % in,in,out mode has functional syntax
:- mode plus(out, in, in) is det. % relational syntax only
:- mode plus(in, out, in) is det. % relational syntax only

>  For the Mercury CLP(R)
>interface, we clearly want to use functional syntax; using relational
>syntax for arithmetic expressions leads to code which is much harder
>to read.

Agreed.  This seems to be the main reason for using functional syntax in
a non-FP way.  With CLP you completely abandon any idea of modes and
determinism.  One possibility is to treat this kind of code specially,
for example, in Sicstus, CLP(R) constraints have to be enclosed within
braces (something Peter hates, mind you) and this may permit more
flexibity.  Another is to (possibly) change how the CLP(R) interface
works - does it really need reversible Mercury functions?  Doesn't the
CLP(R) version of plus just make some connection between its arguments +
result with things inside the solver (rather inefficiently) without
much regard for modes?

Another possibility is to allow multi-moded functions in the language
but design the standard libraries so they are avoided. It would be
useful to be able to easily define predicates which are the
same as these functions but run in different modes (see above).

	lee
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list