[mercury-users] Modes in "int" module.
Ralph Becket
rafe at csse.unimelb.edu.au
Tue Jul 10 12:13:54 AEST 2007
Bartlomiej Szymczak, Monday, 9 July 2007:
> Hello.
>
> I don't understand one thing in the "int" library module:
>
> :- pred int.max(int::in, int::in, int::out) is det.
>
> :- func int + int = int.
> :- mode in + in = uo is det.
>
> Both operations (max and +) have the same type from mathematical point
> of view - they take two numbers and deterministically produce another
> number.
>
> What I don't understand is why + produces result in mode uo. Shouldn't
> it produce result in mode out, like max does?
The uo mode is mainly there for hysterical raisins.
Usually the output of an addition is a new integer, whereas the output
of max is one of its inputs, hence the justification for uo for +, but
not max. In practice we don't properly support uniqueness yet (for which
we're slightly embarrassed!), but we're hoping to get a PhD student on
board to redo the mode system, at which point hopefully uniqueness will
work properly.
> Additionally I don't like that there are only functions to do some
> things. It would be really nice for me if predicate versions were
> provided.
Our convention is that relations with mode (in, in, ..., in, out) is det
should be functions and all others should be predicates. Of course, we
don't strictly stick to this for (a) historical reasons and (b) field
access functions.
> One more problem is that in the documentation the modes for int.plus
> function are not shown:
> :- func int.plus(int, int) = int.
A func with no mode takes the default mode (in, in, ..., in) = out is det.
It's a useful shorthand.
-- Ralph
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list