module Io:Rudimentary I/O-monadsig
..end
type
error =
| |
EndOfFile |
(* | Tried to read beyond end of file | *) |
| |
IntOfString |
(* | Could not convert string to int | *) |
| |
SysError of |
(* | Operating system signaled an error.
The string takes the precise reason. | *) |
type
world
type ('a, 'b)
either
'left
type is for errors, the 'right
type for correct
values.type'a
t =world -> (error, 'a) either * world
'a
takes the current world and produces
either a correct value (of type 'a
or an error
and a new world.val __conjure_up : unit -> world
__conjure_up ()
Conjure up a new "world".
This function should only be used once per program. It is best place in some pre-main initialization code like, for example,
let () =
let world = Io.__conjure_up () in
ignore ((Io.catch (main ()) (fun _error -> ...)) world)
where we call main
with the initial world.val bind : 'a t -> ('a -> 'b t) -> 'b t
bind an_iomonad a_function
Apply a_function
to an_iomonad
producing another IO-monad.
a_function
takes an 'a
value as argument and returns a 'b
IO-monad.
val return : 'a -> 'a t
return a_value
List a_value
into the IO-monad.
val throw : error -> 'a t
throw an_error
Throw an_error
inside the IO-monad.
val catch : 'a t -> (error -> 'a t) -> 'a t
catch an_iomonad a_handler_function
Catch IO-exceptions from an_iomonad
and feed them into
a_handler_function
, which takes an error
value as argument and
returns an 'a
IO-monad.
All of these functions have exactly the same names as their imperative
counterparts. Moreover, they take the same arguments.
val print_char : char -> unit t
print_char a_character
val print_string : string -> unit t
print_string a_string
val print_int : int -> unit t
print_int an_integer
val print_float : float -> unit t
print_float a_float
val print_endline : string -> unit t
print_endline a_string
val print_newline : unit -> unit t
print_newline ()
val prerr_char : char -> unit t
prerr_char a_character
val prerr_string : string -> unit t
prerr_string a_string
val prerr_int : int -> unit t
prerr_int an_integer
val prerr_float : float -> unit t
prerr_float a_float
val prerr_endline : string -> unit t
prerr_endline a_string
val prerr_newline : unit -> unit t
prerr_newline ()
val read_line : unit -> string t
read_line ()
val read_int : unit -> int t
read_int ()
val read_float : unit -> float t
read_float ()
val open_out : string -> Pervasives.out_channel t
open_out a_filename
val output_char : Pervasives.out_channel -> char -> unit t
output_char a_channel a_char
val output_string : Pervasives.out_channel -> string -> unit t
output_string a_channel a_string
val close_out : Pervasives.out_channel -> unit t
close_out a_channel