[m-users.] Mode and inst confusion in ODBC library

Volker Wysk post at volker-wysk.de
Wed Aug 9 14:34:38 AEST 2023


Am Mittwoch, dem 09.08.2023 um 08:16 +1000 schrieb Julien Fischer:
> 
> 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.

Thanks. I won't comment on this...

Bye
Volker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20230809/e355e7a3/attachment.sig>


More information about the users mailing list