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

Laws for polymorphic optics #430

Closed
kenbot opened this issue Dec 4, 2016 · 4 comments
Closed

Laws for polymorphic optics #430

kenbot opened this issue Dec 4, 2016 · 4 comments

Comments

@kenbot
Copy link
Collaborator

kenbot commented Dec 4, 2016

It's a scandal that the laws only apply to the degenerate monomorphic optics -- they're living in sin!

It seems important that the full range of optic behaviour offered by Monocle is well-regulated by laws. A starting point could be unpicking the Haskell Lens functionality so that the laws there can be transcribed. For instance, for Isos:

f . from f ≡ id
from f . f ≡ id

The secret sauce appears to be the Van Laarhoven representation with profunctor constraints, that can unify the various representations with regular functions. We could put all this machinery privately in the laws package, although it might be hard for users to understand the code. The current monomorphic laws are wonderfully crisp and easy to read. Still, the alternative is lawless anarchy!

@julien-truffaut
Copy link
Member

Hum I am wondering how is it possible to do f . from f
if f: PIso[S, T, A, B] then from f: PIso[B, A, T, S] so you shouldn't be able to compose them. I think it is the same point that #428

@kenbot
Copy link
Collaborator Author

kenbot commented Dec 4, 2016

Yep that's where I got stuck - I couldn't get the types to line up.
https://github.com/kenbot/Monocle/blob/piso-laws/core/shared/src/main/scala/monocle/law/PIsoLaws.scala

With regard to the Haskell implementation -- their profunctorial Exchange type is basically the same as Monocle's PIso. They use a type AnIso s t a b, which is basically PIso[...] => PIso[...], and a supertype of the main Iso s t a b. I didn't bother reproducing all the machinery, but I got stuck where I needed an S,T to compose, but had a T,S instead.

It would be great if we could make it work with simple Monocle concepts, all that code is pretty horrid.

@kenbot
Copy link
Collaborator Author

kenbot commented Dec 7, 2016

I found some relevant links:
http://stackoverflow.com/questions/26082221/relationship-between-forward-and-backward-map-in-isomorphism-lens-package
http://comonad.com/reader/2012/mirrored-lenses/

It seems that the S => A and B => T functions must both be bijective, but not necessarily related to each other. The Iso doesn't know about the reverse side of either bijection.

@julien-truffaut
Copy link
Member

Polymorphic optics are likely to get dropped. So I will close that one.

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