package ocamlformat

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Defines the blocking interface for reading and writing to Cohttp streams

type 'a t

'a t represents a blocking monad state

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.

type ic

ic represents an input channel

type oc

oc represents an output channel

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
OCaml

Innovation. Community. Security.