-
Notifications
You must be signed in to change notification settings - Fork 43
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
Style lenses #80
Style lenses #80
Conversation
A few redundent / unused style functions have also been removed. They can be easly implimented in terms of the new lenses.
These can be useful for extracting parts of a diagram (like extracting all paths in a diagram).
The new Semigroup instance for Attributes seems potentially confusing. Is it needed to implement the lenses? Semigroup on Style? Could you explain why we need the instance, maybe as a comment in the code? How much existing user code will this break? I expect not much - the usual code using Otherwise, this looks good, and I agree that it's helpful for arrows & plots, where we manipulate styles directly. @haasn Do you have time to take a look at this? You were working on something similar, right? Except depending on fixpoint changes that haven't landed? |
Thanks for taking a look. The I'd be surprised if any user code is broken. The only ones I could imagine users using is |
OK, sounds good. No need to revert anything, I was just trying to understand. |
This looks similar to parts of what I had implemented, modulo some API changes. The way I approached the API was by providing this function instead: https://github.com/diagrams/diagrams-core/blob/gsoc/src/Diagrams/Core/Style.hs#L221 instead of using the internal mkAttrLens + explicitly providing named instantiations of it. I think I prefer my design for that, but maybe you could find a way to merge them. |
Ah, didn't realise there was other work on it. They turned out pretty similar. I didn't see any need expose
vs
so there's not much difference but I prefer mine :) Are you going to continue with your gsoc? I've got a whole bunch of lens related stuff for diagrams if you're interested. |
I have no immediate plans for continuing it, since development pretty much stalled due to blocking on fixpoint developments. The scope of my project was larger than just adding lenses, which means that those never ended up trickling upstream. If you want to merge our lens approaches and get them into master, I'd greatly appreciate it. For the “attr” vs “atTAttr” distinction, it's been so long that I forgot most of the original motivation for my design choices, but it's possible that I may have picked them so you can use attr with more complicated prisms, too (eg. _Attribute merged with something else). That aside, I simply feel like it's better to provide few, general functions rather than more specific instantiations of them. |
Looks good to me. |
I wouldn't call I'll get lib rebased with HEAD and merge this. |
Not ready to merge:
diagrams-lib
needs to make a few changes before merging.This adds lenses for
Style
s onto attributes, and prisms forPrim
andRNode
. I've also removed some unused functions.The lenses provide valid lenses onto the attributes of a style. Even though you can't traverse over the styles of a diagram yet they're useful for things like
ArrowOpts
(I also deal with them a lot in plots) where you deal with styles explicitly. The lookup is determined by the type of the target. It's possible to specialise these lenses for particular attributes:Another useful trick is using the
Wrapped
instance of attributes to have a lens to the direct value:If an attribute has a default and we can check equality for this default, we can go further by using a
non
oranon
Iso
:This is because having no entry in the style is the same as using the default:
I haven't implemented this in diagrams-lib yet. Is it something we'd want for all attributes? I'm not sure about naming conventions.