I agree that basic (non van Laarhoven) lenses are pretty achievable in OCaml, though I tend to forget about them.
Truly what you want is the "pre-applied" lens or the store comonad
type ('i, 'j) store = { get : 'j; set : 'j -> 'i };;
Then object types can have something like let o = object
val slot = 3
method slot =
{ get = slot
; set = fun slot' -> {< slot = slot' >}
}
end
which has type val o : < slot : ('a, int) store > as 'a
which is kind of a cool pattern. # o#slot.get;;
- : int = 3
# (o#slot.set 10)#slot.get;;
- : int = 10
# o#slot.set o#slot.get;;
- : < slot : ('a, int) store > as 'a = <obj>