Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Read-entire-file/Mercury/read-entire-file.mercury
Normal file
27
Task/Read-entire-file/Mercury/read-entire-file.mercury
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
:- module read_entire_file.
|
||||
:- interface.
|
||||
|
||||
:- import_module io.
|
||||
:- pred main(io::di, io::uo) is det.
|
||||
|
||||
:- implementation.
|
||||
:- import_module string.
|
||||
|
||||
main(!IO) :-
|
||||
io.open_input("file.txt", OpenResult, !IO),
|
||||
(
|
||||
OpenResult = ok(File),
|
||||
io.read_file_as_string(File, ReadResult, !IO),
|
||||
(
|
||||
ReadResult = ok(FileContents),
|
||||
io.write_string(FileContents, !IO)
|
||||
;
|
||||
ReadResult = error(_, IO_Error),
|
||||
io.stderr_stream(Stderr, !IO),
|
||||
io.write_string(Stderr, io.error_message(IO_Error) ++ "\n", !IO)
|
||||
)
|
||||
;
|
||||
OpenResult = error(IO_Error),
|
||||
io.stderr_stream(Stderr, !IO),
|
||||
io.write_string(Stderr, io.error_message(IO_Error) ++ "\n", !IO)
|
||||
).
|
||||
Loading…
Add table
Add a link
Reference in a new issue