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

Integrate with the notion of Lens #4

Open
johnynek opened this issue Jan 2, 2013 · 1 comment
Open

Integrate with the notion of Lens #4

johnynek opened this issue Jan 2, 2013 · 1 comment
Labels

Comments

@johnynek
Copy link
Collaborator

johnynek commented Jan 2, 2013

http://twanvl.nl/blog/haskell/isomorphism-lenses

I think something like:

// Type inference should work without having to specify R in the below unless there are multiple valid bijections
object Lens {
  def get[A,B](a: A)(implicit bij: Bijection[A,(B,_)]): B = bij(a)._1
  def modify[A,B,R](a: A)(update: B => B)(implicit bij: Bijection[A,(B,R)]): A = {
    val decons = bij(a)
    bij.invert((update(decons._1), decons._2))
  }
  def set[A,B,R](a: A, b: B)(implicit bij: Bijection[A,(B,R)]): A = {
    val decons = bij(a)
    bij.invert((b, decons._2))
  } 
}

This relies on having good bijections from A into each of it's parts. It would be great if we could have a way to signify that (B,R) could really be any tuple of B with any other items (e.g. (B,R1,R2,R3...) would work.

@sritchie
Copy link
Collaborator

http://twanvl.nl/blog/haskell/isomorphism-lenses
http://www.cis.upenn.edu/~bcpierce/papers/lenses-etapsslides.pdf -- awesome

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