package algaeff

  1. Overview
  2. Docs

The implementation of the effects.

Signatures of the effects.

Parameters

module Elt : Sigs.Type

Signature

module ID : sig ... end

The type of IDs and its friends.

type id = ID.t

The type of unique IDs. The client should not assume a particular indexing scheme.

val register : Elt.t -> id

Register a new item and get an ID. Note that registering the same item twice will get two different IDs.

val retrieve : id -> Elt.t

Retrieve the item associated with the ID.

val export : unit -> Elt.t Seq.t

Export the internal storage for serialization. Once exported, the representation is persistent and can be traversed without the effect handler.

val run : ?init:Elt.t Seq.t -> (unit -> 'a) -> 'a

run t runs the thunk t and handles the effects for generating unique IDs.

  • parameter init

    The initial storage, which should be the output of some previous export.

val register_printer : ([ `Register of Elt.t | `Retrieve of id | `Export ] -> string option) -> unit

register_printer p registers a printer p via Printexc.register_printer to convert unhandled internal effects into strings for the OCaml runtime system to display. Ideally, all internal effects should have been handled by run and there is no need to use this function, but when it is not the case, this function can be helpful for debugging. The functor UniqueID.Make always registers a simple printer to suggest using run, but you can register new ones to override it. The return type of the printer p should return Some s where s is the resulting string, or None if it chooses not to convert a particular effect. The registered printers are tried in reverse order until one of them returns Some s for some s; that is, the last registered printer is tried first. Note that this function is a wrapper of Printexc.register_printer and all the registered printers (via this function or Printexc.register_printer) are put into the same list.

The input type of the printer p is a variant representation of the internal effects used in this module. They correspond to the effects trigger by register, retrieve and export. More precisely,

  • `Register elt corresponds to the effect triggered by register elt.
  • `Retrieve id corresponds to the effect triggered by retrieve id.
  • `Export corresponds to the effect triggered by export ().
  • since 1.1.0
OCaml

Innovation. Community. Security.