<html aria-label="message body"><head><meta http-equiv="content-type" content="text/html; charset=us-ascii"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">Hi Volker,<div><br></div><div>I just scanned Chapter 8, Higher Order... what is the meaning of the question marks here? I could find no reference.</div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><br></div><div><blockquote type="cite"><br></blockquote></div><div><blockquote type="cite">:- pred ?(list(ta_rule(TKNS)), TKNS, TKNS).</blockquote></div><div><blockquote type="cite">:- mode ?(in(list(ta_rule)), in, out).</blockquote></div><div><br></div></blockquote><div>Thanks,</div><div>Sean</div><div><br id="lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On 21 Sep 2025, at 17:51, Volker Wysk <post@volker-wysk.de> wrote:</div><br class="Apple-interchange-newline"><div><div>Hi, Anders<br><br>You have two errors:<br><br>1. You don't need and can't have the TNKS argument to your ta_rule inst,<br>since it isn't used on the right side.<br><br>2. You need to specify a higher order inst matching your higher order type,<br>for both predicates.<br><br>Do it like this:<br><br>:- type ta_rule(TKNS) == pred(TKNS, TKNS). % 'ta' abbreviates 'type alias'<br>:- inst ta_rule == (pred(in, out) is semidet).<br><br>:- pred ?(list(ta_rule(TKNS)), TKNS, TKNS).<br>:- mode ?(in(list(ta_rule)), in, out).<br><br>:- pred apply_rules(list(ta_rule(TKNS)), TKNS, TKNS).<br>:- mode apply_rules(in(list(ta_rule)), in, out) is semidet.<br><br>Cheers,<br>Volker<br><br>Am Sonntag, dem 21.09.2025 um 18:28 +0200 schrieb Anders Lundstedt:<br><blockquote type="cite">Dear all,<br><br><br>For the purpose of a parser I am writing, I want to have a DCG rule ?<br>taking a list of DCG rules as input and that then tries to apply all<br>rules in the list.<br><br><br>GitHub Gist of the following:<br><br>https://gist.github.com/anderslundstedt/1f5b1d8ad6b4d2404dae4a602d3d920d<br><br><br>My attempt:<br><br>:- type ta_rule(TKNS) == pred(TKNS, TKNS). % 'ta' abbreviates 'type<br>alias'<br>:- inst ta_rule(TKNS) == (pred(in, out) is semidet).<br><br>:- pred ?(list(ta_rule(TKNS)), TKNS, TKNS).<br>:- mode ?(in, in, out).<br>?(RULES) --> (<br> apply_rules(RULES) -> {true};<br> {true}<br>).<br><br>:- pred apply_rules(list(ta_rule(TKNS)), TKNS, TKNS).<br>:- mode apply_rules(in, in, out) is semidet.<br>apply_rules([]) --> {true}.<br>apply_rules([R|RS]) --> R, apply_rules(RS).<br><br><br>Compilation error:<br><br>In clause for `apply_rules(in, in, out)':<br> in argument 1 (i.e. the predicate term) of higher-order predicate<br> call:<br> mode error: variable `R' has instantiatedness `ground',<br> expecting higher-order pred inst of arity 2.<br><br><br>Any advice would be greatly appreciated!<br><br><br><br>Best,<br><br>Anders Lundstedt<br>_______________________________________________<br>users mailing list<br>users@lists.mercurylang.org<br>https://lists.mercurylang.org/listinfo/users<br></blockquote>_______________________________________________<br>users mailing list<br>users@lists.mercurylang.org<br>https://lists.mercurylang.org/listinfo/users<br></div></div></blockquote></div><br></div></body></html>