[m-users.] Higher-order predicate issue
Peter Wang
novalazy at gmail.com
Sat Oct 2 11:57:32 AEST 2021
On Fri, 01 Oct 2021 21:27:40 +0100 "Sean Charles (emacstheviking)" <objitsu at gmail.com> wrote:
> Hi,
>
> I am trying to pass around a predicate to execute at a later point in my translation process:
>
> :- type renderer == (pred(instruction, lstring, rop_error, tcon, tcon)).
> :- inst renderer == (pred(in, in, out, in, out) is det).
>
> then to set the renderer:
>
> Renderer = target_c.render
>
> then I have a work in progress evaluation predicate:
>
> :- pred eval(renderer::in, location::in, instruction::in, lsnode::in,
> renderout::out, tcon::in, tcon::out) is semidet.
The mode 'in' is defined as 'ground >> ground',
so the pred-mode declaration declares that the first argument has
initial inst 'ground' and final inst 'ground'.
>
> eval(Render, Pos, defvar, Args, Result, !T) :-
> trace[io(!Dbg), runtime(env("FELT_TRN"))]
> (sdump($pred, $line, Args, !Dbg)),
>
> ( if Args = [tk(Pos, VarName)] then
> %
> % this it not working well
> % ...what can be done to make it better ?
> %
> 348 Render(defvar, lstring(Pos, VarName), CodeM, !T),
Renderer has inst 'ground' here, meaning it has no higher-order inst
information, so it cannot be called. (It is possible to call a
higher-order *function* term without higher-order inst information,
but that is a special case.)
You need to change the mode of the first argument from 'in' to
'in(renderer)', which expands to 'renderer >> renderer',
where 'renderer' refers to the inst you have defined earlier.
There is no implied connection between the type name 'renderer'
and the inst name 'renderer'.
Peter
More information about the users
mailing list