module Io:sig..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 ('left, 'right) either
'left type is for errors, the 'right type for correct
values.type'at =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 tbind 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 treturn a_value
List a_value into the IO-monad.
val throw : error -> 'a tthrow an_error
Throw an_error inside the IO-monad.
val catch : 'a t -> (error -> 'a t) -> 'a tcatch 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 tprint_char a_characterval print_string : string -> unit tprint_string a_stringval print_int : int -> unit tprint_int an_integerval print_float : float -> unit tprint_float a_floatval print_endline : string -> unit tprint_endline a_stringval print_newline : unit -> unit tprint_newline ()val prerr_char : char -> unit tprerr_char a_characterval prerr_string : string -> unit tprerr_string a_stringval prerr_int : int -> unit tprerr_int an_integerval prerr_float : float -> unit tprerr_float a_floatval prerr_endline : string -> unit tprerr_endline a_stringval prerr_newline : unit -> unit tprerr_newline ()val read_line : unit -> string tread_line ()val read_int : unit -> int tread_int ()val read_float : unit -> float tread_float ()val open_out : string -> Pervasives.out_channel topen_out a_filenameval output_char : Pervasives.out_channel -> char -> unit toutput_char a_channel a_charval output_string : Pervasives.out_channel -> string -> unit toutput_string a_channel a_stringval close_out : Pervasives.out_channel -> unit tclose_out a_channel