Files
mercury/tests/hard_coded/bidirectional.m
Julien Fischer 459847a064 Move the univ, maybe, pair and unit types from std_util into their own
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.
2006-03-29 08:09:58 +00:00

73 lines
1.6 KiB
Mathematica

% Regression test.
% Tests predicates with multiple modes,
% reordering, and partially instantiated data structures.
:- module bidirectional.
:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is det.
:- implementation.
:- import_module string, maybe, list, char.
main -->
format_list_of_int(read, List),
format_list_of_int(write, List).
:- type rw ---> read ; write.
:- mode read == in(bound(read)).
:- mode write == in(bound(write)).
:- pred format_list_of_int(rw, list(int), io__state, io__state).
:- mode format_list_of_int(write, in, di, uo) is det.
:- mode format_list_of_int(read, out, di, uo) is det.
format_list_of_int(RW, List) -->
format_int(RW, Val),
( { Val = no, List = [] }
; { Val = yes(X), List = [X|_] }
),
( { List = [] }
; { List = [_|_] },
format_list_of_int(RW, Xs),
{ List = [_|Xs] }
).
:- pred format_int(rw, maybe(int), io__state, io__state).
:- mode format_int(write, in, di, uo) is det.
:- mode format_int(read, out, di, uo) is det.
format_int(read, Val) -->
my_read_line(MaybeLine),
{ if MaybeLine = ok(Chars),
string__from_char_list(Chars, Line),
string__to_int(Line, X)
then
Val = yes(X)
else
Val = no
}.
format_int(write, yes(X)) -->
io__write_int(X),
io__write_string("\n").
format_int(write, no) -->
io__write_string("\n").
:- pred my_read_line(io__result(list(char)), io__state, io__state).
:- mode my_read_line(out, di, uo) is det.
my_read_line(Result) -->
io__read_line(Result0),
{
Result0 = ok(Line0),
list__reverse(Line0, ['\n'|LineRev])
->
list__reverse(LineRev, Line),
Result = ok(Line)
;
Result = Result0
}.