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

struct->struct lens? #267

Open
AlexKnauth opened this issue Dec 11, 2015 · 1 comment
Open

struct->struct lens? #267

AlexKnauth opened this issue Dec 11, 2015 · 1 comment

Comments

@AlexKnauth
Copy link
Collaborator

Something like this:

(struct foo (a b c))
(struct bar (x y z))
(define foo->bar-lens
  (struct->struct-lens foo bar))
> (lens-view foo->bar-lens (foo 1 2 3))
(bar 1 2 3)

Or possibly something that would allow fields to change order?

(define foo->bar-lens2
  (struct->struct-lens foo bar [a y] [b z] [c x]))
> (lens-view foo->bar-lens2 (foo 1 2 3))
(bar 3 1 2)

Or even something that would allow that other lenses in between?

(struct foo (a b c))
(struct bar (x y z))
(define foo->bar-lens3
  (struct->struct-lens foo bar
    [a first-lens y]
    [b second-lens z]
    [c third-lens x]))
> (lens-view foo->bar-lens3 (foo '(1 2 3) '(4 5 6) '(7 8 9)))
(bar 9 1 5)

The first two could be isomorphism-lenses as well, but the third one couldn't.

@jackfirth
Copy link
Owner

I think the third is easily defined in terms of lens-join/struct, so I'm not sure that one's necessary. I definitely think it should possible to change the order of the fields.

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