[m-users.] A predicate taking a lists of predicates as input?
Volker Wysk
post at volker-wysk.de
Mon Sep 22 02:51:12 AEST 2025
Hi, Anders
You have two errors:
1. You don't need and can't have the TNKS argument to your ta_rule inst,
since it isn't used on the right side.
2. You need to specify a higher order inst matching your higher order type,
for both predicates.
Do it like this:
:- type ta_rule(TKNS) == pred(TKNS, TKNS). % 'ta' abbreviates 'type alias'
:- inst ta_rule == (pred(in, out) is semidet).
:- pred ?(list(ta_rule(TKNS)), TKNS, TKNS).
:- mode ?(in(list(ta_rule)), in, out).
:- pred apply_rules(list(ta_rule(TKNS)), TKNS, TKNS).
:- mode apply_rules(in(list(ta_rule)), in, out) is semidet.
Cheers,
Volker
Am Sonntag, dem 21.09.2025 um 18:28 +0200 schrieb Anders Lundstedt:
> Dear all,
>
>
> For the purpose of a parser I am writing, I want to have a DCG rule ?
> taking a list of DCG rules as input and that then tries to apply all
> rules in the list.
>
>
> GitHub Gist of the following:
>
> https://gist.github.com/anderslundstedt/1f5b1d8ad6b4d2404dae4a602d3d920d
>
>
> My attempt:
>
> :- type ta_rule(TKNS) == pred(TKNS, TKNS). % 'ta' abbreviates 'type
> alias'
> :- inst ta_rule(TKNS) == (pred(in, out) is semidet).
>
> :- pred ?(list(ta_rule(TKNS)), TKNS, TKNS).
> :- mode ?(in, in, out).
> ?(RULES) --> (
> apply_rules(RULES) -> {true};
> {true}
> ).
>
> :- pred apply_rules(list(ta_rule(TKNS)), TKNS, TKNS).
> :- mode apply_rules(in, in, out) is semidet.
> apply_rules([]) --> {true}.
> apply_rules([R|RS]) --> R, apply_rules(RS).
>
>
> Compilation error:
>
> In clause for `apply_rules(in, in, out)':
> in argument 1 (i.e. the predicate term) of higher-order predicate
> call:
> mode error: variable `R' has instantiatedness `ground',
> expecting higher-order pred inst of arity 2.
>
>
> Any advice would be greatly appreciated!
>
>
>
> Best,
>
> Anders Lundstedt
> _______________________________________________
> users mailing list
> users at lists.mercurylang.org
> https://lists.mercurylang.org/listinfo/users
More information about the users
mailing list