7 ms·
> OCaml classes allow row polymorphism, but disallow immutable updates (immutable updates meaning create a new object with everything the same, but one element
by emillon 12y ago
> OCaml classes allow row polymorphism, but disallow immutable updates (immutable updates meaning create a new object with everything the same, but one element different.)
There's a functional update construct for objects:
http://caml.inria.fr/pub/docs/manual-ocaml/objectexamples.html#sec36 http://caml.inria.fr/pub/docs/manual-ocaml/objectexamples.ht...
It works like { r with field = value }.
- tel 12y agoThat syntax works for records not objects. The {< _ = _ >} syntax is sort-of equivalent except it can only be used within method definitions (!) and is therefore too restricted. Instead, try taking a look at the store-comonad mechanism I've got below: https://news.ycombinator.com/item?id=9213482 https://news.ycombinator.com/item?id=9213482