blob: af5aab5b83628d3b4d58cd4e485852aebcb55f8d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
signature SIMPLE_IO = sig
type instream
type outstream
type vector
val openIn: string-> instream
val closeIn: instream -> unit
val openOut: string-> outstream
val closeOut: outstream -> unit
val inputAll: instream -> vector
val output: outstream * vector -> unit
end
functor ManagedIO(SimpleIO:SIMPLE_IO) = struct
val inputAll = SimpleIO.inputAll
val output = SimpleIO.output
fun withInputFile fname manage = let
val file = SimpleIO.openIn fname
in
manage file
finally SimpleIO.closeIn file
end
fun withOutputFile fname manage = let
val file = SimpleIO.openOut fname
in
manage file
finally SimpleIO.closeOut file
end
end
|