Skip to content
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

lens-join/* functions produce non-lenses when views overlap #301

Open
lexi-lambda opened this issue Nov 27, 2017 · 2 comments
Open

lens-join/* functions produce non-lenses when views overlap #301

lexi-lambda opened this issue Nov 27, 2017 · 2 comments

Comments

@lexi-lambda
Copy link
Contributor

It’s quite easy to produce a lens with, for example, lens-join/list that is not actually a lens; that is, it does not respect the lens laws. Specifically, the produced lens violates set-get consistency when the views of the sublenses overlap. Here’s an example:

> (let ([l (lens-join/list first-lens first-lens)])
    (lens-view l (lens-set l '(a b) '(1 2))))
'(2 2)

This produces '(2 2), but the set-get consistency law demands that it produce '(1 2).

The documentation sort of notes this in the following comment:

If any of the lenses share views, then when setting the later lenses override the earlier ones.

However, I don’t think this is phrased quite scarily enough. I think it should be reworded to make it quite clear that the lens-join/* functions do not produce legal lenses when given lenses with overlapping views.

@AlexKnauth
Copy link
Collaborator

AlexKnauth commented Nov 27, 2017

A (lens-join/list X-piece-lens ...) lens only follows the lens laws when this is true for all X.

(lens-set* X {~seq X-piece-lens (lens-view X-piece-lens X)} ...) = X

(Edit: no, the problem is somewhere else)

@AlexKnauth
Copy link
Collaborator

AlexKnauth commented Nov 27, 2017

But that's not the only condition. It also needs these properties for all sets of X-piece ...:

(lens-view X-piece-lens (lens-set* X {~seq X-piece-lens X-piece} ...)) = X-piece
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants