1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162# 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. *)(* *)(**************************************************************************)moduletypeS=sig(** Defines the blocking interface for reading and writing to Cohttp
streams *)(** ['a t] represents a blocking monad state *)type'atval(>>=):'at->('a->'bt)->'bt(** [a >>= b] will pass the result of [a] to the [b] function. This is a
monadic [bind]. *)valreturn:'a->'at(** [return a] will construct a constant IO value. *)(** [ic] represents an input channel *)typeic(** [oc] represents an output channel *)typeocvalread:ic->Csexp.toptiontvalwrite:oc->Csexp.tlist->unitt(** 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