[m-rev.] Another compiler bug with almost the same code

Zoltan Somogyi zoltan.somogyi at runbox.com
Thu Nov 9 04:44:31 AEDT 2023


On 2023-11-09 04:24 +11:00 AEDT, "Volker Wysk" <post at volker-wysk.de> wrote:
> The following, slightly modified code leads to another compiler bug (so it
> seems):
> 
> 
> :- pred with_connection(pred(int, T, io, io), T, io, io).
> %:- mode with_connection(pred(in, out, di, uo) is det,      out, di, uo) is
> det.
> :- mode with_connection(pred(in, out, di, uo) is cc_multi, out, di, uo) is
> cc_multi.
> 
> with_connection(Pred, PRes, !IO) :-
> 
>     Cleanup =
>         (pred(io.ok::out, !.IO1::di, !:IO1::uo) is cc_multi :-
>             !:IO1 = !.IO1),
> 
>     exception.finally(
>         Pred(1),    % Line 28
>         PRes,
>         Cleanup,
>         _CleanupRes,
>         !IO).
> 
> 
> Even though the second mode line is commented out, it doesn't compile:
> 
> 
> finally.m:028: In clause for predicate `with_connection'/4:
> finally.m:028:   in argument 1 of call to predicate `exception.finally'/6:
> finally.m:028:   in unification of argument
> finally.m:028:   and term `Pred(V_21)':
> finally.m:028:   type error in argument of higher-order term (with arity 1).
> finally.m:028:   Functor (Pred) has type
> finally.m:028:     some [T] (pred(int, T, io.state, io.state)),
> finally.m:028:   expected type was
> finally.m:028:     func(V_5) = V_6.
> 
> 
> Why is the expected type a function? That must be wrong.

In Mercury, a term where a variable is applied to a list of one or more arguments,
the variable is expected to be a function. It seems that you are attempting to
curry Pred, but Mercury allows only named predicates and functions to be
curried; you cannot curry a predicate- or function-valued variable.

Zoltan.


More information about the reviews mailing list