-
Notifications
You must be signed in to change notification settings - Fork 13
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
Consider adding zippers? #19
Comments
Instead of having an inductive datatype for representing a zipper, we can also use a "list" of the various fragments. Due to the type indexes, we can't use a standard list but we need something fancier. To show that we got this right, "prove" the equivalence of the two representations by defining an isomorphism between the two. I must say, I am positively amazed by how well GHC supported me in this task. Agda has still the upper hand with its better tool support, but writing this code was too much fun.
Looks, nice! I'm snowed under with teaching at the moment, so I'll have to wait with taking a closer look. Are you using the same approach as in Scrap-Your-Zippers, or is it something else? In any case, I would definitely like to have it in the library. Older GHC compatibility is not so important now that GHC 7.8.3 is in the Platform. (There are also things in the library that could be modernized; e.g. some type classes with fundeps that could be rewritten using closed type families.) |
Happy you're interested!
I didn't read that paper yet (and I'm snowed under with moving, so I shouldn't read it so quickly), but it might well be. I was inspired by your related work section (in the ICFP 2012 paper), in particular this paragraph:
However, I treat AST as a binary tree to derive a zipper, so each "zipper piece" (ASTZipperF) contains one left or right sibling, not siblings as in the above. |
Ah, I see. I suppose that can be useful, but one probably also wants zippers where one can only focus fully applied symbols, as that's what corresponds to nodes in a normal data type. (OTOH I don't really have a usecase for either version.) But please send a pull request for your zipper implementation when it's ready. |
I see your point — I'll take a look at it, and at a pull request, when I next have time. (Semester's starting here :-( ). I have some use cases in mind where this kind of zipper might be useful. |
It seems that each "fragment" of "your zipper" (i.e., only focusing on fully applied symbols) is one of "my zippers", where both sides of the zippers have type See ASTZipperLF for what seems an implementation (not sure yet). |
Now that I think about it, what I was after was probably just to be able to navigate through fully applied trees -- it doesn't really matter what the internal representation is. I played with your code, and came to the following functions for navigating horizontally:
It seems harder to implement |
Makes sense, though I'm not sure of the details and can't fully get in (should find a 4-hour block for looking at this properly). Here's what I figured in less than that:
The real problem is for typing the operations. With some thought, I believe that the runtime evidence for running the operation is in the data structures themselves, though I'm not 100% sure. But if
|
@emilaxelsson , your paper mentions that adding generic zippers based on Syntactic seems possible. It turns out that you're right, at least on a modern GHC (I've used 7.8.3, mostly because of pattern synonyms) and type-level lists (I've also done it without, but the resulting API has less precise types):
https://github.com/Blaisorblade/learning-syntactic/blob/master/src/Zippers.hs
If compatibility with older GHC is interesting, one could probably avoid DataKinds by doing the desugaring by hand, and maybe also other features.
Also, I just realized I picked the MIT license instead of the BSD license, but that's not a problem (and I could even relicense the code).
BTW, I'm a PhD student in the area, so should you think this is worth writing about, I'd be interested. Right now it does not seem so interesting to deserve a paper on its own, but it seems like it would belong in a revised version of your paper.
The text was updated successfully, but these errors were encountered: