-
Notifications
You must be signed in to change notification settings - Fork 0
/
it_Types.ml
59 lines (44 loc) · 1.49 KB
/
it_Types.ml
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(* +
The [place] type represents the place where exception
was raised. For now, it's a name of IO function returned
an error.
*)
type place = string;
(* +
IO exception, carrying the real IO exception and the place
(usually function name) where it was raised.
*)
exception EIO of (exn * place);
(* +
Sometimes it's more convenient to have an IO result wrapped
in value with type [res 'a], than having to [IO.catch] errors.
See function [mres] in functor.
*)
type res +'a = [= `Ok of 'a | `Error of exn ]
;
(* +
This is a signature for IO monad. These functions and types are used
by Iteratees functor. It's possible that your implementation of IO
have much more functions than MonadIO, so you should not restrict
your IO implementation by this MonadIO signature.
*)
module type MonadIO
=
sig
type m +'a;
value return : 'a -> m 'a;
value bind : ('a -> m 'b) -> m 'a -> m 'b;
value bind_rev : m 'a -> ('a -> m 'b) -> m 'b;
value error : exn -> m 'a;
value catch : (unit -> m 'a) -> (exn -> m 'a) -> m 'a;
type output_channel;
value stdout : output_channel;
value write : output_channel -> string -> m unit;
type input_channel;
value open_in : string -> m input_channel;
value close_in : input_channel -> m unit; (* Lwt_io.close inch *)
value read_into : input_channel -> string -> int -> int -> m int;
(* in lwt: read_into ic buffer offset length *)
value runIO : m 'a -> [= `Ok of 'a | `Error of exn ];
end
;