[m-users.] Returning a predicate from a function
Sean Charles (emacstheviking)
objitsu at gmail.com
Fri Dec 23 01:22:52 AEDT 2022
Literally cutting and pasting and compile I get:
tests.m:028: In clause for function `f_ln'/1:
tests.m:028: error: undefined predicate `is'/2.
Which is not your error, have you pasted the right code?
> On 22 Dec 2022, at 11:52, Mark Clements <mark.clements at ki.se> wrote:
>
> Dear Mercury users,
>
> 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?
>
> Sincerely, Mark.
>
> -----
>
> :- module tests.
>
> :- interface.
> :- import_module io.
> :- pred main(io::di, io::uo) is det.
>
> :- implementation.
> :- import_module float, ranges, solutions.
> :- use_module math.
>
> main(!IO) :-
> test1(!IO), % OK
> test2(!IO). % Does not compile
>
> :- pred test1(io::di, io::uo) is det.
> test1(!IO) :-
> Data = (pred(Y::out) is nondet :- nondet_member(I,range(1,5)), Y = float(I)), % some data
> LnData = (pred(Y::out) is nondet :- Data(X), Y = math.ln(X)), % a transformation
> aggregate(LnData, print_line, !IO).
>
> :- pred test2(io::di, io::uo) is det.
> test2(!IO) :-
> Data = (pred(Y::out) is nondet :- nondet_member(I,range(1,5)), Y = float(I)), % some data
> LnData = f_ln(Data), %% This transformation does not compile:(
> aggregate(LnData, print_line, !IO).
>
> :- func f_ln(pred(float)::(pred(out) is nondet)) = (pred(float)::(pred(out) is nondet)).
> f_ln(Pred) = (pred(Y::out) is nondet :- Pred(X), Y is math.ln(X)).
>
>
>
> När du skickar e-post till Karolinska Institutet (KI) innebär detta att KI kommer att behandla dina personuppgifter. Här finns information om hur KI behandlar personuppgifter <https://ki.se/medarbetare/integritetsskyddspolicy>.
>
> Sending email to Karolinska Institutet (KI) will result in KI processing your personal data. You can read more about KI’s processing of personal data here <https://ki.se/en/staff/data-protection-policy>.
> _______________________________________________
> users mailing list
> users at lists.mercurylang.org <mailto:users at lists.mercurylang.org>
> https://lists.mercurylang.org/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20221222/e888d788/attachment-0001.html>
More information about the users
mailing list