Files
mercury/tests/hard_coded/higher_order_mutable.m
Zoltan Somogyi e78cfaaa8c Allow higher order inst info in mutables.
compiler/parse_mutable.m:
compiler/parse_type_name.m:
    As above.

tests/hard_coded/higher_order_mutable.{m,exp}:
    A new test case for the new capability, checking whether we can call
    a closure we got out of a mutable.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2024-07-24 09:46:00 +02:00

66 lines
1.5 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module higher_order_mutable.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
:- implementation.
:- import_module int.
:- import_module list.
:- import_module string.
%---------------------------------------------------------------------------%
:- mutable(numerals, (pred(int::in, string::out) is semidet), english, ground,
[untrailed, attach_to_io_state]).
%---------------------------------------------------------------------------%
main(!IO) :-
test(1, !IO),
test(2, !IO),
test(3, !IO),
test(4, !IO),
io.nl(!IO),
set_numerals(spanish, !IO),
test(1, !IO),
test(2, !IO),
test(3, !IO),
test(4, !IO).
:- pred test(int::in, io::di, io::uo) is det.
test(N, !IO) :-
get_numerals(Numerals, !IO),
( if Numerals(N, NStr) then
io.format("numeral %d -> %s\n", [i(N), s(NStr)], !IO)
else
io.format("numeral %d is unknown\n", [i(N)], !IO)
).
%---------------------------------------------------------------------------%
:- pred english(int::in, string::out) is semidet.
english(1, "one").
english(2, "two").
english(3, "three").
:- pred spanish(int::in, string::out) is semidet.
spanish(1, "una").
spanish(2, "dos").
spanish(3, "tres").