mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-21 00:39: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.
76 lines
1.3 KiB
Mathematica
76 lines
1.3 KiB
Mathematica
% Some very simple tests of type_to_univ and univ_to_type.
|
|
|
|
:- module test_univ.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io__state::di, io__state::uo) is det.
|
|
|
|
:- implementation.
|
|
:- import_module univ, list, bool.
|
|
|
|
main -->
|
|
( { test1 } ->
|
|
io__write_string("test 1 ok\n")
|
|
;
|
|
io__write_string("test 1 failed\n")
|
|
),
|
|
( { test2 } ->
|
|
io__write_string("test 2 failed\n")
|
|
;
|
|
io__write_string("test 2 ok\n")
|
|
),
|
|
( { test3 } ->
|
|
io__write_string("test 3 failed\n")
|
|
;
|
|
io__write_string("test 3 ok\n")
|
|
),
|
|
( { test4(Compare) } ->
|
|
( { Compare = no } ->
|
|
io__write_string("test 4 ok\n")
|
|
;
|
|
io__write_string("test 4 comparison failed\n")
|
|
)
|
|
;
|
|
io__write_string("test 4 type_to_univ failed\n")
|
|
).
|
|
|
|
:- pred test1 is semidet.
|
|
|
|
test1 :-
|
|
X = 1,
|
|
type_to_univ(X, UnivX),
|
|
Y = 1,
|
|
type_to_univ(Y, UnivY),
|
|
UnivX = UnivY.
|
|
|
|
:- pred test2 is semidet.
|
|
|
|
test2 :-
|
|
X = 1,
|
|
type_to_univ(X, UnivX),
|
|
Y = 2,
|
|
type_to_univ(Y, UnivY),
|
|
UnivX = UnivY.
|
|
|
|
:- pred test3 is semidet.
|
|
|
|
test3 :-
|
|
X = 1,
|
|
type_to_univ(X, UnivX),
|
|
type_to_univ(Y, UnivX),
|
|
Y = "string".
|
|
|
|
:- pred test4(bool::out) is semidet.
|
|
|
|
test4(Compare) :-
|
|
X = 1,
|
|
type_to_univ(X, UnivX),
|
|
type_to_univ(Y, UnivX),
|
|
% The comparison should establish the type of Y as integer (same as X)
|
|
( Y = 2 ->
|
|
Compare = yes
|
|
;
|
|
Compare = no
|
|
).
|