An implementation of optics in Elm.
Lens that cannot change type of the object.
Prism that cannot change type of the object.
Traversal that cannot change type of the object.
Iso that cannot change type of the object.
A lens constructor.
Parameters are: getter and setter.
If the lens can change type of an object, the setter must return the object of a new type.
A prism constructor.
Parameters are: reconstructor and a splitter.
Reconstructor takes a final value and constructs a final object.
The splitter turns initial object either to final object directly (if initial object is of wrong variant),
or spits out a.
A traversal constructor.
Parameters are: toList and a mapper.
We need toList, because there is no Foldable typeclass in Elm.
The mapper is a "mapSomething" function update s.
An isomorphism constructor.
An identity optic.
Lens usagePrism usageCheck if s is related to a prism.
Note: You can change Y to pr here and it will still compile.
I restricted it to prisms, because semantics for traversals
is kinda be questionable.
Traversals)
A lens, prism or a traversal.
The
prandlsare used to trackreviewandgetcapabilities, leave them being type variables. The consumers of lens will try to unify either of these withYtype (=()).The
s,t,aandbare "input object type", "output object type", "input part type" and "output part type", accordingly.This means that you can get
afroms, and given a functiona -> bmake atout ofs.Later in this text I will use term "final" for "out" types and "initial" for "in" types.