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

set-mapper-lens #200

Open
AlexKnauth opened this issue Aug 31, 2015 · 4 comments
Open

set-mapper-lens #200

AlexKnauth opened this issue Aug 31, 2015 · 4 comments
Labels

Comments

@AlexKnauth
Copy link
Collaborator

Should this try to be consistent with set-map (going from sets to lists), or should it go from sets to sets?
To follow the lens laws sets to sets would make more sense, and for things like making a hash-rekey-lens using a hash->set-lens isomorphism (see #199 (comment)), but what do you think?

@AlexKnauth
Copy link
Collaborator Author

I'm running into problems with this and ordering.
If I define it naively like this:

(define (set-mapper-lens lens)
  (make-lens
   (λ (tgt)
     (list->set (set-map tgt (lens-view lens _))))
   (λ (tgt nvw)
     (list->set (map (lens-set lens _ _) (set->list tgt) (set->list nvw))))))

Then a test case like this (which worked for lists) fails because of ordering in the lens-set case:
(Edit: this was just a bad test case because of a copy/paste error, but the concept of the ordering messing with things is still there, see next comment)

(check-equal? (lens-set (set-mapper-lens first-lens) (set '(a b) '(c d) '(e f)) (set 1 2 3))
              (set '("a" b) '("c" d) '("e" f)))

This fails with this failure message:

--------------------
FAILURE
actual:     #<set: (3 f) (1 b) (2 d)>
expected:   #<set: ("e" f) ("a" b) ("c" d)>
name:       check-equal?
location:   (#<path:/Users/Alex/Documents/GitHub/lens/unstable/lens/mapper.rkt> 60 2 1823 142)
expression: (check-equal? (lens-set (set-mapper-lens first-lens) (set '(a b) '(c d) '(e f)) (set 1 2 3)) (set '("a" b) '("c" d) '("e" f)))

. Check failure
--------------------

@AlexKnauth
Copy link
Collaborator Author

Oh wait I accidentally put (set '("a" b) '("c" d) '("e" f)) instead of (set '(1 b) '(2 d) '(3 f)).
This case actually happened to work with that fixed, but it won't always work in other cases, right?

@AlexKnauth
Copy link
Collaborator Author

If I wanted to do a test case like that I would want:

(check-equal? (lens-set (set-mapper-lens first-lens) (set '(a b) '(c d) '(e f)) (set "a" "c" "e"))
              (set '("a" b) '("c" d) '("e" f)))

But that actually works too. Weird.

@jackfirth
Copy link
Owner

I've thought about this one too and I'm really not sure, because you can't swap out a set of views with a new set of views without knowing which view to swap out for which. I think it'd be more useful to have hash->assoc isomorphims that take an ordering procedure and figure out how to apply those to these sorts of problems.

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

No branches or pull requests

2 participants