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

Draft optics implementation #13

Closed
wants to merge 31 commits into from

Conversation

AriFordsham
Copy link
Collaborator

Initial draft implementation.

@AriFordsham AriFordsham changed the title Ari/optics Draft optics implementation Jul 11, 2022
@L-as
Copy link
Member

L-as commented Jul 11, 2022 via email

@AriFordsham
Copy link
Collaborator Author

What obstacles are there to 'efficiently?'

I'm planning on implementing profunctor optics in a way that makes sense for Plutarch lenses.

  • As much work should be done in Haskell, at Plutarch compile time.
  • I need to ensure not to introduce superfluous pcon/pmatch into the body of combinators and lenses themselves.
  • Is there a risk of redundant pcon/pmatch in a composition of optics, which the composition function needs to deal with? It doesn't seem obvious to me that there is.
  • The general problem of redundant matches might be unsolvable in library, and may need an optimizer pass.

Are there any efficiency considerations I am missing?

@L-as
Copy link
Member

L-as commented Jul 12, 2022

Consider combining Lens' a b and Lens' a c into Lens' a (b, c). How do you this efficiently?
Relying on the backend to optimise it is not good design.

@AriFordsham
Copy link
Collaborator Author

  • Optics for EPair and EEither
  • type aliases PLens and PPrism
  • typeclass PChoice for PPrism
  • some useful combintors in Core

@AriFordsham AriFordsham requested a review from L-as July 14, 2022 16:21
@AriFordsham
Copy link
Collaborator Author

We have optics!

  • Plutarch-free profunctor and optics stacks based on the Cont monad - essentially replacing every a -> b with a -> Cont r b
  • Optics for EPair and EEither. These essentially use Haskell Either in Plutarch!

@L-as
Copy link
Member

L-as commented Aug 3, 2022 via email

@AriFordsham
Copy link
Collaborator Author

Happy to change that back. I use partial-type-signatures warnings with HLS quite heavily in my workflow.
shell.nix on master has ghc923, which is what I'm using.

newtype CStar r f a b = CStar { runCStar :: a -> Cont r (f b) }

class CProfunctor r p where
cdimap :: (a -> Cont r b) -> (c -> Cont r d) -> p b (Cont r c) -> p a (Cont r d)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should still be p b c and p a d.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then CProfunctor r -> would not be implementable, but you could make a newtype where it is implementable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try that. It is more elegant, but breaks too many things.

@L-as
Copy link
Member

L-as commented Aug 10, 2022 via email

@AriFordsham
Copy link
Collaborator Author

Not having r on the right of an arrow breaks a lot of inference and requires many type applications. In addition, something hard broke, I can't remember what. It seemed fixable, but not worth the trouble. I'm happy to try again if you think it's worth it.

@L-as
Copy link
Member

L-as commented Aug 10, 2022 via email

@L-as L-as linked an issue Aug 12, 2022 that may be closed by this pull request
Not actually a traversal, but allows easy definition of one.

With example of use
@AriFordsham
Copy link
Collaborator Author

PConstrained implemented

@AriFordsham
Copy link
Collaborator Author

  • Completed ptraverse for types with one parameter
  • Implemented plist in terms of ptraverse

We won't really know if this works until we have a backend to test with.

@L-as
Copy link
Member

L-as commented Sep 11, 2022

Amazing! Perhaps we should work on getting a backend to work again.

@L-as L-as closed this May 28, 2023
@L-as
Copy link
Member

L-as commented May 28, 2023

Plutarch has changed too much for this to be mergible.

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

Successfully merging this pull request may close these issues.

Optics
2 participants