mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-28 15:54:18 +00:00
Estimated hours taken: 2
Branches: main
Start integrating the new stream typeclasses into the rest of the
standard library.
library/io.m:
Make the standard text and binary files streams from the io
modules instances of the new stream typeclasses.
(Note: I've only made instances of the obvious types, we
will probably want to define a few more, e.g.
:- type line ---> line(string)
).
Unrelated change: move the implementation of the function
version of io.error_message next to its predicate version.
library/pprint.m:
Generalise pprint.write so that it can write docs to any
arbitrary string writer.
tests/hard_coded/Mmakefile:
tests/hard_coded/stream_tests.{m,exp,data}:
A short test of the new stream typeclasses.
43 lines
958 B
Mathematica
43 lines
958 B
Mathematica
:- module stream_test.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module char.
|
|
:- import_module list.
|
|
:- import_module pprint.
|
|
:- import_module stream.
|
|
:- import_module univ.
|
|
|
|
:- type foo ---> foo ; bar ; baz.
|
|
|
|
main(!IO) :-
|
|
io.stdout_stream(Stdout, !IO),
|
|
put(Stdout, 561, !IO),
|
|
put(Stdout, "\nHello World!\n", !IO),
|
|
put(Stdout, 'a', !IO),
|
|
put(Stdout, "\n", !IO),
|
|
put(Stdout, univ([foo, bar, baz]), !IO),
|
|
put(Stdout, "\n", !IO),
|
|
list.duplicate(10, foo, ListFoo),
|
|
pprint.write(Stdout, 4, to_doc(ListFoo), !IO),
|
|
io.nl(Stdout, !IO),
|
|
io.stdin_stream(Stdin, !IO),
|
|
input_stream_fold(Stdin, char_list_cons, [], PartialResult, !IO),
|
|
(
|
|
PartialResult = ok(Result),
|
|
io.write(Result, !IO),
|
|
io.nl(!IO)
|
|
;
|
|
PartialResult = error(_, _),
|
|
io.write_string("TEST FAILED\n", !IO)
|
|
).
|
|
|
|
:- pred char_list_cons(char::in, list(char)::in, list(char)::out) is det.
|
|
|
|
char_list_cons(X, Xs, [ X | Xs ]).
|