<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div>Changing f_ln to:</div><div><br></div><div><div>:- func f_ln(pred(float)::(pred(out) is nondet)) = (pred(float)::(pred(out) is nondet)).</div><div>f_ln(Pred) = (pred(Y::out) is nondet :- Pred(X), Y <b>=</b> math.ln(X)).    %<====== you have 'is' here, not equals, possibly a Prolog relapse! :)</div><div><br></div><div>gives me this compiler output:</div><div><br></div><div><div>➜  tmp mmc -E tests.m</div><div>tests.m:025: In clause for `test2(di, uo)':</div><div>tests.m:025:   mode error in conjunction. The next 2 error messages indicate</div><div>tests.m:025:   possible causes of this error.</div><div>tests.m:025:</div><div>tests.m:024:   In clause for `test2(di, uo)':</div><div>tests.m:024:   in the return value of call to function `tests.f_ln'/1:</div><div>tests.m:024:   mode error: variable `LnData' has instantiatedness `free',</div><div>tests.m:024:   expected instantiatedness was `(pred(out) is nondet)'.</div><div>tests.m:025:</div><div>tests.m:025:   In clause for `test2(di, uo)':</div><div>tests.m:025:   in call to predicate `solutions.aggregate'/4:</div><div>tests.m:025:   mode error: arguments</div><div>tests.m:025:   `LnData, V_14, STATE_VARIABLE_IO_0, STATE_VARIABLE_IO' have the</div><div>tests.m:025:   following insts:</div><div>tests.m:025:     free,</div><div>tests.m:025:     /* unique */ (pred(in, di, uo) is det),</div><div>tests.m:025:     unique,</div><div>tests.m:025:     free</div><div>tests.m:025:   which does not match any of the modes for predicate</div><div>tests.m:025:   `solutions.aggregate'/4.</div><div>tests.m:025:   The first argument `LnData' has inst `free', which does not</div><div>tests.m:025:   match any of those modes.</div><div>tests.m:028: In clause for `f_ln((pred(out) is nondet)) = (pred(out) is</div><div>tests.m:028:   nondet)':</div><div>tests.m:028:   In unification of `HeadVar__2' with</div><div>tests.m:028:   `lambda([Pred::(pred(out) is nondet)] ... )':</div><div>tests.m:028:   mode error: attempt at higher-order unification.</div><div>tests.m:028:   Cannot unify two terms of type `(pred float)'.</div><div>tests.m:028:   Your code is trying to test whether two predicates are equal, by</div><div>tests.m:028:   unifying them. In the general case, testing equivalence of</div><div>tests.m:028:   predicates is an undecidable problem, and so this is not allowed</div><div>tests.m:028:   by the Mercury mode system. In some cases, you can achieve the</div><div>tests.m:028:   same effect by writing an explicit universal quantification,</div><div>tests.m:028:   e.g. `all [X] call(PredA, X) <=> call(PredB, X)', instead of</div><div>tests.m:028:   `PredA = PredB'.</div></div><div><br></div><div><br></div><div>Hopefully somebody else can help you resolve it, as I am sure that it can be done.</div><div><br></div><div><br></div><div><br><blockquote type="cite"><div>On 22 Dec 2022, at 11:52, Mark Clements <mark.clements@ki.se> wrote:</div><br class="Apple-interchange-newline"><div><div class="elementToProof"><span class="ContentPasted0 elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);">Dear Mercury users,<br></span></div><div class="elementToProof"><span class="ContentPasted0" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);"><br></span></div><div class="elementToProof"><span class="ContentPasted0" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);">Is there any way to write a function that takes a predicate and returns a transformed predicate without (a) naming a new predicate or (b) using a lambda? In practice, I would like to move the lambda to a function. However, the following code gives an error: "Cannot unify two terms of type `(pred float)'". Can I assume that this is outside of Mercury's mode system?</span></div><div class="elementToProof"><span class="ContentPasted0" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);"><br></span></div><div class="elementToProof"><span class="ContentPasted0" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);">Sincerely, Mark.</span></div><div class="elementToProof"><span class="ContentPasted0" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);"><br></span></div><div class="elementToProof"><span class="ContentPasted0" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);">-----</span></div><div class="elementToProof"><span class="ContentPasted0" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);"><br></span></div><div class="elementToProof"><span class="ContentPasted0 ContentPasted1" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);">:- module tests.<div class="FluidPluginCopy"><br class="ContentPasted1"></div><div class="FluidPluginCopy ContentPasted1">:- interface.</div><div class="FluidPluginCopy ContentPasted1">:- import_module io.</div><div class="FluidPluginCopy ContentPasted1">:- pred main(io::di, io::uo) is det.</div><div class="FluidPluginCopy"><br class="ContentPasted1"></div><div class="FluidPluginCopy ContentPasted1">:- implementation.</div><div class="FluidPluginCopy ContentPasted1">:- import_module float, ranges, solutions.</div><div class="FluidPluginCopy ContentPasted1">:- use_module math.</div><div class="FluidPluginCopy"><br class="ContentPasted1"></div><div class="FluidPluginCopy ContentPasted1">main(!IO) :-</div><div class="FluidPluginCopy ContentPasted1">    test1(!IO), % OK</div><div class="FluidPluginCopy ContentPasted1">    test2(!IO). % Does not compile</div><div class="FluidPluginCopy"><br class="ContentPasted1"></div><div class="FluidPluginCopy ContentPasted1">:- pred test1(io::di, io::uo) is det.</div><div class="FluidPluginCopy ContentPasted1">test1(!IO) :- </div><div class="FluidPluginCopy ContentPasted1">    Data = (pred(Y::out) is nondet :- nondet_member(I,range(1,5)), Y = float(I)), % some data<br></div><div class="FluidPluginCopy ContentPasted1">    LnData = (pred(Y::out) is nondet :- Data(X), Y = math.ln(X)), % a transformation<br></div><div class="FluidPluginCopy ContentPasted1">    aggregate(LnData, print_line, !IO).</div><div class="FluidPluginCopy"><br class="ContentPasted1"></div><div class="FluidPluginCopy ContentPasted1">:- pred test2(io::di, io::uo) is det.</div><div class="FluidPluginCopy ContentPasted1">test2(!IO) :- </div><div class="FluidPluginCopy ContentPasted1">    Data = (pred(Y::out) is nondet :- nondet_member(I,range(1,5)), Y = float(I)), % some data<br></div><div class="FluidPluginCopy ContentPasted1">    LnData = f_ln(Data), %% This transformation does not compile:(<br></div><div class="FluidPluginCopy ContentPasted1">    aggregate(LnData, print_line, !IO).</div><div class="FluidPluginCopy"><br class="ContentPasted1"></div><div class="FluidPluginCopy ContentPasted1">:- func f_ln(pred(float)::(pred(out) is nondet)) = (pred(float)::(pred(out) is nondet)).</div><div class="FluidPluginCopy ContentPasted1">f_ln(Pred) = (pred(Y::out) is nondet :- Pred(X), Y is math.ln(X)).</div><br></span></div><div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Times; -webkit-text-stroke-color: rgb(0, 0, 0); min-height: 14px;"><span class="s1" style="font-kerning: none;"></span><br></div><div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Times; -webkit-text-stroke-color: rgb(0, 0, 0); min-height: 14px;"><span class="s1" style="font-kerning: none;"></span><br></div><div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Times; -webkit-text-stroke-color: rgb(0, 0, 0);"><span class="s1" style="font-kerning: none;"><i>När du skickar e-post till Karolinska Institutet (KI) innebär detta att KI kommer att behandla dina personuppgifter. </i><a href="https://ki.se/medarbetare/integritetsskyddspolicy"><span class="s2" style="font-kerning: none; color: rgb(0, 0, 238); -webkit-text-stroke-color: rgb(0, 0, 238);">Här finns information om hur KI behandlar personuppgifter</span></a>. </span></div><div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Times; -webkit-text-stroke-color: rgb(0, 0, 0); min-height: 14px;"><span class="s1" style="font-kerning: none;"></span><br></div><div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Times; -webkit-text-stroke-color: rgb(0, 0, 0);"><span class="s1" style="font-kerning: none;"><i>Sending email to Karolinska Institutet (KI) will result in KI processing your personal data.</i> <a href="https://ki.se/en/staff/data-protection-policy"><span class="s2" style="font-kerning: none; color: rgb(0, 0, 238); -webkit-text-stroke-color: rgb(0, 0, 238);">You can read more about KI’s processing of personal data here</span></a>. </span></div>_______________________________________________<br>users mailing list<br><a href="mailto:users@lists.mercurylang.org">users@lists.mercurylang.org</a><br><a href="https://lists.mercurylang.org/listinfo/users">https://lists.mercurylang.org/listinfo/users</a></div></blockquote></div></div><br class="Apple-interchange-newline"><div><br><blockquote type="cite"><div>On 22 Dec 2022, at 11:52, Mark Clements <mark.clements@ki.se> wrote:</div><br class="Apple-interchange-newline"><div><meta charset="UTF-8"><div class="elementToProof" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span class="ContentPasted0 elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);">Dear Mercury users,<br></span></div><div class="elementToProof" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span class="ContentPasted0" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);"><br></span></div><div class="elementToProof" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span class="ContentPasted0" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);">Is there any way to write a function that takes a predicate and returns a transformed predicate without (a) naming a new predicate or (b) using a lambda? In practice, I would like to move the lambda to a function. However, the following code gives an error: "Cannot unify two terms of type `(pred float)'". Can I assume that this is outside of Mercury's mode system?</span></div><div class="elementToProof" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span class="ContentPasted0" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);"><br></span></div><div class="elementToProof" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span class="ContentPasted0" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);">Sincerely, Mark.</span></div><div class="elementToProof" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span class="ContentPasted0" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);"><br></span></div><div class="elementToProof" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span class="ContentPasted0" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);">-----</span></div><div class="elementToProof" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span class="ContentPasted0" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);"><br></span></div><div class="elementToProof" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span class="ContentPasted0 ContentPasted1" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);">:- module tests.<div class="FluidPluginCopy"><br class="ContentPasted1"></div><div class="FluidPluginCopy ContentPasted1">:- interface.</div><div class="FluidPluginCopy ContentPasted1">:- import_module io.</div><div class="FluidPluginCopy ContentPasted1">:- pred main(io::di, io::uo) is det.</div><div class="FluidPluginCopy"><br class="ContentPasted1"></div><div class="FluidPluginCopy ContentPasted1">:- implementation.</div><div class="FluidPluginCopy ContentPasted1">:- import_module float, ranges, solutions.</div><div class="FluidPluginCopy ContentPasted1">:- use_module math.</div><div class="FluidPluginCopy"><br class="ContentPasted1"></div><div class="FluidPluginCopy ContentPasted1">main(!IO) :-</div><div class="FluidPluginCopy ContentPasted1">    test1(!IO), % OK</div><div class="FluidPluginCopy ContentPasted1">    test2(!IO). % Does not compile</div><div class="FluidPluginCopy"><br class="ContentPasted1"></div><div class="FluidPluginCopy ContentPasted1">:- pred test1(io::di, io::uo) is det.</div><div class="FluidPluginCopy ContentPasted1">test1(!IO) :-<span class="Apple-converted-space"> </span></div><div class="FluidPluginCopy ContentPasted1">    Data = (pred(Y::out) is nondet :- nondet_member(I,range(1,5)), Y = float(I)), % some data<br></div><div class="FluidPluginCopy ContentPasted1">    LnData = (pred(Y::out) is nondet :- Data(X), Y = math.ln(X)), % a transformation<br></div><div class="FluidPluginCopy ContentPasted1">    aggregate(LnData, print_line, !IO).</div><div class="FluidPluginCopy"><br class="ContentPasted1"></div><div class="FluidPluginCopy ContentPasted1">:- pred test2(io::di, io::uo) is det.</div><div class="FluidPluginCopy ContentPasted1">test2(!IO) :-<span class="Apple-converted-space"> </span></div><div class="FluidPluginCopy ContentPasted1">    Data = (pred(Y::out) is nondet :- nondet_member(I,range(1,5)), Y = float(I)), % some data<br></div><div class="FluidPluginCopy ContentPasted1">    LnData = f_ln(Data), %% This transformation does not compile:(<br></div><div class="FluidPluginCopy ContentPasted1">    aggregate(LnData, print_line, !IO).</div><div class="FluidPluginCopy"><br class="ContentPasted1"></div><div class="FluidPluginCopy ContentPasted1">:- func f_ln(pred(float)::(pred(out) is nondet)) = (pred(float)::(pred(out) is nondet)).</div><div class="FluidPluginCopy ContentPasted1">f_ln(Pred) = (pred(Y::out) is nondet :- Pred(X), Y is math.ln(X)).</div><br></span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: 400; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Times; -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0); min-height: 14px; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none;"><span class="s1" style="font-kerning: none;"></span><br></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: 400; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Times; -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0); min-height: 14px; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none;"><span class="s1" style="font-kerning: none;"></span><br></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: 400; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Times; -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none;"><span class="s1" style="font-kerning: none;"><i>När du skickar e-post till Karolinska Institutet (KI) innebär detta att KI kommer att behandla dina personuppgifter.<span class="Apple-converted-space"> </span></i><a href="https://ki.se/medarbetare/integritetsskyddspolicy"><span class="s2" style="text-decoration: underline; font-kerning: none; color: rgb(0, 0, 238); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 238);">Här finns information om hur KI behandlar personuppgifter</span></a>.<span class="Apple-converted-space"> </span></span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: 400; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Times; -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0); min-height: 14px; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none;"><span class="s1" style="font-kerning: none;"></span><br></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-weight: 400; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Times; -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none;"><span class="s1" style="font-kerning: none;"><i>Sending email to Karolinska Institutet (KI) will result in KI processing your personal data.</i><span class="Apple-converted-space"> </span><a href="https://ki.se/en/staff/data-protection-policy"><span class="s2" style="text-decoration: underline; font-kerning: none; color: rgb(0, 0, 238); -webkit-text-stroke-width: 0px; -webkit-text-stroke-color: rgb(0, 0, 238);">You can read more about KI’s processing of personal data here</span></a>.<span class="Apple-converted-space"> </span></span></div><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;">_______________________________________________</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;">users mailing list</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><a href="mailto:users@lists.mercurylang.org" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">users@lists.mercurylang.org</a><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><a href="https://lists.mercurylang.org/listinfo/users" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">https://lists.mercurylang.org/listinfo/users</a></div></blockquote></div><br></body></html>