-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(WIP) A mess of new concepts #45
base: master
Are you sure you want to change the base?
Conversation
Idea: |
Nope: the correct linear rank-1 form of a lens is |
78ccfa9
to
e6d2834
Compare
note to self: try having both |
e6d2834
to
95814ce
Compare
95814ce
to
dad3c10
Compare
@Divesh-Otwani Apologies for leaving this (and other branches) in such a state. Feel free to get in touch with me if you'd like some help tidying it up or just a better idea of what was going through my head with some of the stuff I left unfinished! |
@b-mehta Thanks -- will get in touch! |
For most of the things introduced here, see #79 . Which covers the same ground except:
I'm not convinced the getters with I'm leaving the PR open, still, as an inspiration as I'm trying to tackle the traversal story. See also #190 (and soon more). |
WIP:
Changes introduced:
Prelude.Traversable t
in whichor
Data.Traversable t
in whichSo, there should be two notions of a
Traversal
, and there must be two versions of theWandering
type class. Here, due to lack of imagination, they are prefixedP
andD
.More linearity for
get
andset
. Naturally, these two cannot be linear as usually written:get
discards part of its argument, andset
throws away the old information. However they can be given type signatures which reflect these facts and are stronger than just non-linear arrows.Setting is easy to deal with: we can just return the original value that was replaced, then running
snd
afterwards recovers the non-linearset
. The idea is thatset'
can have a type signature that promises more, but degrades nicely to the standard one.Getting is a little more complex: We define a 'wastebasket' of resources,
Top
, which has the property thatforall x. x ->. Top
is inhabited (uniquely). It thus forms a (linear) monoid.The use of
Top
here is that arrowsa ->. (Top, b)
are something of an intermediate betweena ->. b
anda -> b
; they promise thata
is not used more than once, but can't promise that all ofa
is used. For example, we can define(a,b) ->. (Top, b)
, which gets the second component and 'throws away' the first component. Again, if the extra linearity promise isn't helpful, post-composing withsnd
will recover the usualget
.(Aside: the writer monad writing to
Top
has its Kleisli arrows as the above arrows, so we can nicely compose these functions: maybe there is some use to a promise that the argument is used no more than once)To write: the
lens
constructor and a deconstructor?Pair
. Wrapped semigroups