Library
Module
Module type
Parameter
Class
Class type
This module contains what might be described as faux lenses. This includes support for composition, getting, setting, etc.
An open type that represents a field on a record.
For example,
type t = {
x : int
}
would be described as X : (t, int) field
.
A polymorphic function that returns the field's value from the type.
A polymorphic function that returns the type with the field set to the value.
exception Diff_field of error
val name : ('a, 'b) t -> string option
name f
returns the previously registered name for f
, if one exists.
cons l r
is a field that first indexes l
and then r
.
opt_map f
monadically binds f
into an optional field.
register ?name field getter setter
registers getter
and setter
(and optionally name
) to field
.
val pp : Format.formatter -> ('a, 'b) t -> unit
val pp_error : Format.formatter -> error -> unit
module Infix : sig ... end
val get : 'a -> ('a, 'b) t -> 'b
get v field
gets field
from v
, raising Diff_field error
on exception.
val get_opt : 'a -> ('a, 'b) t -> 'b option
get_opt v field
gets field
from v
, returning None
on exception.
get_opt v field
gets field
from v
, returning Error (`Diff_field e)
on exception.
val set : 'a -> ('a, 'b) t -> 'b -> 'a
set v field x
sets field
in v
to x
, raising Diff_field error
on exception
val set_opt : 'a -> ('a, 'b) t -> 'b -> 'a option
set_opt v field x
sets field
in v
to x
, returning None
on exception