mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-30 08:44:37 +00:00
Estimated hours taken: 18 Branches: main Move the univ, maybe, pair and unit types from std_util into their own modules. std_util still contains the general purpose higher-order programming constructs. library/std_util.m: Move univ, maybe, pair and unit (plus any other related types and procedures) into their own modules. library/maybe.m: New module. This contains the maybe and maybe_error types and the associated procedures. library/pair.m: New module. This contains the pair type and associated procedures. library/unit.m: New module. This contains the types unit/0 and unit/1. library/univ.m: New module. This contains the univ type and associated procedures. library/library.m: Add the new modules. library/private_builtin.m: Update the declaration of the type_ctor_info struct for univ. runtime/mercury.h: Update the declaration for the type_ctor_info struct for univ. runtime/mercury_mcpp.h: runtime/mercury_hlc_types.h: Update the definition of MR_Univ. runtime/mercury_init.h: Fix a comment: ML_type_name is now exported from type_desc.m. compiler/mlds_to_il.m: Update the the name of the module that defines univs (which are handled specially by the il code generator.) library/*.m: compiler/*.m: browser/*.m: mdbcomp/*.m: profiler/*.m: deep_profiler/*.m: Conform to the above changes. Import the new modules where they are needed; don't import std_util where it isn't needed. Fix formatting in lots of modules. Delete duplicate module imports. tests/*: Update the test suite to confrom to the above changes.
99 lines
1.3 KiB
Mathematica
99 lines
1.3 KiB
Mathematica
:- module cond.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module list, int, maybe.
|
|
|
|
:- type t
|
|
---> empty
|
|
; node(t, int, t).
|
|
|
|
main(!IO) :-
|
|
test_maybe(!IO),
|
|
test_maybe(!IO),
|
|
test_maybe(!IO),
|
|
test_maybe(!IO),
|
|
test_string(!IO),
|
|
test_string(!IO),
|
|
test_tree(!IO),
|
|
test_tree(!IO),
|
|
test_tree(!IO),
|
|
test_tree(!IO),
|
|
test_tree(!IO).
|
|
|
|
:- pred test_maybe(io::di, io::uo) is det.
|
|
|
|
test_maybe(!IO) :-
|
|
p(no, A),
|
|
p(yes(2), B),
|
|
p(yes(3), C),
|
|
io__write([A, B, C], !IO),
|
|
io__nl(!IO).
|
|
|
|
:- pred test_string(io::di, io::uo) is det.
|
|
|
|
test_string(!IO) :-
|
|
q("abc", A),
|
|
io__write_string(A, !IO),
|
|
io__nl(!IO),
|
|
q("def", B),
|
|
io__write_string(B, !IO),
|
|
io__nl(!IO),
|
|
q("ghi", C),
|
|
io__write_string(C, !IO),
|
|
io__nl(!IO).
|
|
|
|
:- pred test_tree(io::di, io::uo) is det.
|
|
|
|
test_tree(!IO) :-
|
|
r(1, A),
|
|
s(A, AA),
|
|
io__write(AA, !IO),
|
|
io__nl(!IO),
|
|
r(2, B),
|
|
s(B, BB),
|
|
io__write(BB, !IO),
|
|
io__nl(!IO).
|
|
|
|
:- pred p(maybe(int)::in, maybe(int)::out) is det.
|
|
|
|
p(X, Y) :-
|
|
(
|
|
X = no,
|
|
Y = no
|
|
;
|
|
X = yes(Z),
|
|
Y = yes(Z + 1)
|
|
).
|
|
|
|
:- pred q(string::in, string::out) is det.
|
|
|
|
q(X, Y) :-
|
|
( X = "abc" ->
|
|
Y = "xabcx"
|
|
; X = "def" ->
|
|
Y = "ydefy"
|
|
;
|
|
Y = "else"
|
|
).
|
|
|
|
:- pred r(int::in, t::out) is det.
|
|
|
|
r(X, Y) :-
|
|
( X = 0 ->
|
|
Y = empty
|
|
;
|
|
r(X - 1, S),
|
|
Y = node(S, X, S)
|
|
).
|
|
|
|
:- pred s(t::in, t::out) is det.
|
|
|
|
s(X, X).
|