[m-users.] Mode and inst confusion in ODBC library
Julien Fischer
jfischer at opturion.com
Wed Aug 9 08:16:40 AEST 2023
On Tue, 8 Aug 2023, Volker Wysk wrote:
> Hi
>
> In the ODBC extra library, there's this:
>
> -----snip-----
> :- type odbc.transaction(T) == pred(T, odbc.state, odbc.state).
> :- mode odbc.transaction == (pred(out, di, uo) is det).
>
> % ...
>
> :- pred odbc.transaction(data_source::in, user_name::in, password::in,
> transaction(T)::transaction,
> odbc.result(T)::out, io::di, io::uo) is det.
> -----snip-----
>
> The mode of the fourth argument of the predicate is a (higher order) inst,
> not a mode - ?? According to Ralph Becket's Mercury tutorial, the mode of an
> argument is a mapping from the instantiation before the call to after the
> call of the predicate. And it's written "Before >> After" (or defined this
> way).
>From section 9.4 "Higher-order insts and modes" of the reference manual:
As a convenience, the language allows you to write a higher order mode
using the same syntax as a higher order inst. If HOInst has the form of
a higher order inst, then writing HOInst where a mode is required is the
same as writing ‘in(HOInst)’, which is in turn equivalent to ‘HOInst >>
HOInst’. Therefore, you can omit ‘in()’ around the higher order inst of
an input argument. For example,
:- mode foldl(in(pred(in, in, out) is det), in, in, out) is det.
can also be written as
:- mode foldl(pred(in, in, out) is det, in, in, out) is det.
though the former may be easier to understand.
Julien.
More information about the users
mailing list