[m-dev.] file streams
Michael Day
mcda at cat.cs.mu.OZ.AU
Thu Dec 23 21:10:46 AEDT 1999
Here is an example of io streams slightly more interesting than standard
output. Files. You can open 'em. You can close 'em. You can seek on 'em.
No, you can't move, link, unlink or stat 'em. They're only streams.
Michael
%-----------------------------------------------------------------------------%
% Copyright (C) 1993-1999 The University of Melbourne.
% This file may only be copied under the terms of the GNU Library General
% Public License - see the file COPYING.LIB in the Mercury distribution.
%-----------------------------------------------------------------------------%
%
% File: file.m.
% Main author: mcda.
% Stability: exceptionally low.
%
% This file provides interfaces for file streams.
%
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- module file.
:- interface.
:- import_module io, stream, string.
%-----------------------------------------------------------------------------%
:- type file__input.
:- instance stream__stream(file__input).
:- instance stream__input(file__input).
:- instance stream__seekable(file__input).
:- type file__output.
:- instance stream__stream(file__output).
:- instance stream__output(file__output).
:- instance stream__seekable(file__output).
:- type file__duplex.
:- instance stream__stream(file__duplex).
:- instance stream__input(file__duplex).
:- instance stream__output(file__duplex).
:- instance stream__duplex(file__duplex).
:- instance stream__seekable(file__duplex).
:- type file__result(T)
---> ok(T)
; error(string).
%-----------------------------------------------------------------------------%
% Predicates to open file streams.
:- pred file__open_input(string, file__result(file__input), io__state, io__state).
:- mode file__open_input(in, uo, di, uo) is det.
:- pred file__open_output(string, file__result(file__output), io__state, io__state).
:- mode file__open_output(in, uo, di, uo) is det.
:- pred file__open_duplex(string, file__result(file__duplex), io__state, io__state).
:- mode file__open_duplex(in, uo, di, uo) is det.
% Predicates to close file streams.
:- pred file__close_input(file__input, io__state, io__state).
:- mode file__close_input(di, di, uo) is det.
:- pred file__close_output(file__output, io__state, io__state).
:- mode file__close_output(di, di, uo) is det.
:- pred file__close_duplex(file__duplex, io__state, io__state).
:- mode file__close_duplex(di, di, uo) is det.
%-----------------------------------------------------------------------------%
:- implementation.
...
:- end_module file.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list