Files
mercury/tests/hard_coded/user_compare.m
Julien Fischer 5d0acda798 Delete obsolete predicates from builtin module.
library/builtin:
    Delete the promise_only_solution/1 and promise_only_solution_io/4. Both
    have have been marked as obsolete since 2015.

    Also delete the non-public impure versions of those, get_one_solution/1
    and get_one_solution_io/4. Implementing the pure versions was the only
    use of these.

compiler/hlds_goal.m:
    Delete a reference to promise_only_solution in a comment.

tests/declarative_debugger/trust.exp:
tests/declarative_debugger/trust.inp:
tests/declarative_debugger/trust_1.m:
     Replace a call to promise_only_solution/1; this does simplify this test
     a little, but does not affect what the trust_1 module was testing, namely
     the user-defined comparison on the type exported by that module.

tests/declarative_debugger/exceptions.m:
tests/hard_coded/myset.m:
tests/hard_coded/user_compare.m:
tests/valid_seq/intermod_nested_module_bug2.m:
extras/curs/samples/nibbles.m:
     Replace calls to the now deleted predicates.
2022-04-13 15:09:21 +10:00

127 lines
3.6 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module user_compare.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int.
main(!IO) :-
compare(Result, foo(1), foo(2)),
io.write_line(Result, !IO),
( if unify(foo(1), foo(1)) then
io.write_string("succeeded\n", !IO)
else
io.write_string("failed\n", !IO)
),
( if foreign(1) = foreign(1) then
io.write_string("succeeded\n", !IO)
else
io.write_string("failed\n", !IO)
),
( if foreign(2) = foreign(3) then
io.write_string("failed\n", !IO)
else
io.write_string("succeeded\n", !IO)
),
compare(Result2, foreign(3), foreign(2)),
io.write_line(Result2, !IO).
:- type foo
---> foo(int)
where comparison is compare_foo.
% Reverse the comparison of the integers.
%
:- pred compare_foo(comparison_result::uo, foo::in, foo::in) is det.
compare_foo(Res, Foo1, Foo2) :-
promise_equivalent_solutions [Res] (
Foo1 = foo(Int1),
Foo2 = foo(Int2),
compare(Res, Int2, Int1)
).
:- type foreign.
:- pragma foreign_type(c, foreign, "int") where
equality is foreign_equals, comparison is foreign_compare.
:- pragma foreign_type("C#", foreign, "int") where
equality is foreign_equals, comparison is foreign_compare.
:- pragma foreign_type("Java", foreign, "Integer") where
equality is foreign_equals, comparison is foreign_compare.
:- pred foreign_equals(foreign::in, foreign::in) is semidet.
:- pragma foreign_proc(c,
foreign_equals(Foreign1::in, Foreign2::in),
[will_not_call_mercury, promise_pure],
"
SUCCESS_INDICATOR = (Foreign1 == Foreign2);
").
:- pragma foreign_proc("C#",
foreign_equals(Foreign1::in, Foreign2::in),
[will_not_call_mercury, promise_pure],
"
SUCCESS_INDICATOR = (Foreign1 == Foreign2);
").
:- pragma foreign_proc("Java",
foreign_equals(Foreign1::in, Foreign2::in),
[will_not_call_mercury, promise_pure],
"
SUCCESS_INDICATOR = (Foreign1 == Foreign2);
").
:- pred foreign_compare `with_type` compare(foreign) `with_inst` compare.
foreign_compare(Result, Foreign1, Foreign2) :-
foreign_compare_2(Result0, Foreign1, Foreign2),
Result = ( Result0 < 0 -> (<) ; Result0 = 0 -> (=) ; (>) ).
% Reverse the comparison of the integers.
%
:- pred foreign_compare_2(int::out, foreign::in, foreign::in) is det.
:- pragma foreign_proc(c,
foreign_compare_2(Result::out, Foreign1::in, Foreign2::in),
[will_not_call_mercury, promise_pure],
"
Result = (Foreign1 < Foreign2 ? 1 : (Foreign1 == Foreign2 ? 0 : -1));
").
:- pragma foreign_proc("C#",
foreign_compare_2(Result::out, Foreign1::in, Foreign2::in),
[will_not_call_mercury, promise_pure],
"
Result = (Foreign1 < Foreign2 ? 1 : (Foreign1 == Foreign2 ? 0 : -1));
").
:- pragma foreign_proc("Java",
foreign_compare_2(Result::out, Foreign1::in, Foreign2::in),
[will_not_call_mercury, promise_pure],
"
Result = (Foreign1 < Foreign2 ? 1 : (Foreign1 == Foreign2 ? 0 : -1));
").
:- func foreign(int) = foreign.
:- pragma foreign_proc(c,
foreign(Int::in) = (Foreign::out),
[will_not_call_mercury, promise_pure],
"
Foreign = Int;
").
:- pragma foreign_proc("C#",
foreign(Int::in) = (Foreign::out),
[will_not_call_mercury, promise_pure],
"
Foreign = Int;
").
:- pragma foreign_proc("Java",
foreign(Int::in) = (Foreign::out),
[will_not_call_mercury, promise_pure],
"
Foreign = Int;
").