Source

amall / src / amall_types.ml

Full commit
type res 'a = [= `Ok of 'a | `Error of exn ]
;

module type IO_Type =
  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;
    value write_from : output_channel -> string -> int -> int -> m int;

    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 -> res 'a;


    value flush : output_channel -> m unit;

    value printf : format4 'a unit string (m unit) -> 'a;

    value close_out : output_channel -> m unit;


    value run_and_ignore_result : m unit -> unit;


    type server;

    value establish_server :
      ?buffer_size:int ->
      ?backlog:int ->
      Unix.sockaddr ->
      ((input_channel * output_channel) -> unit) ->
      server
    ;

    value shutdown_server : server -> unit
    ;

    value wait_server : server -> m unit
    ;

  end
;


(*
value stdin = Lwt_io.stdin;

value printf fmt = Printf.ksprintf (write stdout) fmt;

value flush = Lwt_io.flush;

value close_out = Lwt_io.close;

*)

(*
module Test = (IO_Lwt : IO_Type)
;
*)


module type FUNCTOR
 =
  sig
    type t 'a;
    value fmap : ('a -> 'b) -> t 'a -> t 'b;
  end
;

module type MONAD_SEQUENCE
 =
  sig
    type m 'a;

    value return : 'a -> m 'a;
    value bind_rev : m 'a -> ('a -> m 'b) -> m 'b;

    value sequence_array : array (m 'a) -> m (array 'a);
  end
;