Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on OCaml: Objects. Parent comment
Truly what you want is the "pre-applied" lens or the store comonad
type ('i, 'j) store = { get : 'j; set : 'j -> 'i };;
let o = object val slot = 3 method slot = { get = slot ; set = fun slot' -> {< slot = slot' >} } end
val o : < slot : ('a, int) store > as 'a
# 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>
Truly what you want is the "pre-applied" lens or the store comonad
Then object types can have something like which has type which is kind of a cool pattern.