package ocamlformat

  1. Overview
  2. Docs

Source file IO.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
60
61
62
# 1 "lib-rpc/IO.ml"
(**************************************************************************)
(*                                                                        *)
(*                              OCamlFormat                               *)
(*                                                                        *)
(*            Copyright (c) Facebook, Inc. and its affiliates.            *)
(*                                                                        *)
(*      This source code is licensed under the MIT license found in       *)
(*      the LICENSE file in the root directory of this source tree.       *)
(*                                                                        *)
(**************************************************************************)

module type S = sig
  (** Defines the blocking interface for reading and writing to Cohttp
      streams *)

  (** ['a t] represents a blocking monad state *)
  type 'a t

  val ( >>= ) : 'a t -> ('a -> 'b t) -> 'b t
  (** [a >>= b] will pass the result of [a] to the [b] function. This is a
      monadic [bind]. *)

  val return : 'a -> 'a t
  (** [return a] will construct a constant IO value. *)

  (** [ic] represents an input channel *)
  type ic

  (** [oc] represents an output channel *)
  type oc

  val read : ic -> Csexp.t option t

  val write : oc -> Csexp.t list -> unit t

  (** A basic implementation of this module can be:

      {[
        module IO = struct
          type 'a t = 'a

          type ic = in_channel

          type oc = out_channel

          let ( >>= ) x f = f x

          let return x = x

          let read ic =
            match Csexp.input ic with
            | Ok x -> return (Some x)
            | Error _ -> return None

          let write oc lx =
            List.iter (Csexp.to_channel oc) lx ;
            Stdlib.flush oc ;
            return ()
        end
      ]} *)
end
OCaml

Innovation. Community. Security.