Source

parvel / parvel_types.ml

The branch 'net-base' does not exist.
(* +
   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 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 flush : output_channel -> m unit;
    value close_out : output_channel -> 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 -> res 'a;


    (* parvel additions: *)

    module Mq
     :
      sig
        type t 'a;
        value create : unit -> t 'a;

        exception Full;

        value set_block_limit : t 'a -> int -> unit;
        value set_fail_limit : t 'a -> int -> unit;

        value put : t 'a -> 'a -> m unit;
        value put_blocking : t 'a -> 'a -> m unit;

        value take : t 'a -> m 'a;

        value idle_reader_exists : t 'a -> bool;
      end
    ;

    value run_and_ignore_result : m unit -> unit;
    value join : list (m unit) -> m unit;

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


    (* временно, будет меняться: *)
    type sink 'a  (* посмотреть на новые Lwt.u, должно быть -'a. *)
     and source +'a;
    value pipe1 : unit -> (source 'a * sink 'a);
    value put_sink : sink 'a -> 'a -> unit;
    value wait_source : source 'a -> m 'a;
    (* . *)

  end
;


module Test_Parvel_IO = (Parvel_IO : MonadIO)
;