-
Notifications
You must be signed in to change notification settings - Fork 67
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
"Functored" AST #98
Comments
I'd like to understand this better. Maybe you could give a small example, with a very abbreviated version of the pandoc types (e.g. with just Str, Emph, Para, and BlockQuote). As for the application, it's hard for me to see what you're trying to accomplish just from the types you give. I assume you're familiar with our existing |
Yeah sure, I would be happy to make the example. |
Fixes jgm#98 See the issue for details of why this is useful
OK see #99 I frequent concern when this sort of thing comes up is breaking downstream code. If that is a concern for you, I am happy to rename the variants and create a bunch of compatibility patterns |
obsidiansystems/dombuilder-pandoc#1 shows how I would change the DOM builder to use this. The "prime" functions are not recursive, and thus can be reused to render something like data MyInline
= Regular (InlineF MyInline) -- fixed typo was `Inline` before
| ReatliveLink Attr [MyInline] MyRoute Text which would accurately represent a document with checked relative URLs. |
Should that be One question is how many changes would be needed to the pandoc code base if pandoc-types were to change in this way. |
Yes, thanks!
Indeed. I wanted to wait to hear your thoughts first, but I am happy to write those pattern synonyms and then make the (far more minimal) changes in |
Here is a report from another project that saw great utility out of structuring their AST in this way: http://newartisans.com/2018/04/win-for-recursion-schemes/ I thought it would be useful to note here. |
Thanks @madeline-os, I was completely blanking on where the existing literature was on this technique. |
The one downside I can think off is that the change would make pandoc less accessible to newcomers. However, I believe that this is not as big a problem anymore. Pandoc's code base reflects more and more of the complexity that's inherent to the problems it solves, and this would be just another step in that direction. I note that the "functorization" could potentially be used to solve jgm/pandoc#684. |
OK I created pattern synonyms such that that the PR should be almost breakage free. (Exception is cannot associate data constructors to type synonyms for aliases, which are used for tables.) |
Have you tried compiling pandoc against the altered pandoc-types, to see where breakage might happen? |
@jgm trying that now. |
pandoc/pandoc-lua-marshal#5 jgm/pandoc#8084 are the changes. As you can see are quite minimal and just making some imports uglier because of the GHC deficiency. |
Wow, that's quite impressive. I will try to have a closer look at this before long, but it might be a couple weeks. |
Sounds good. Just let me know about any and all questions once you do :). |
Fixes jgm#98 See the issue for details of why this is useful
Fixes jgm#98 See the issue for details of why this is useful
@jgm thanks for giving this another look and repeatedly enabling CI for me. All 3 PRs:
are now passing, anything more you need from me? |
Many thanks! I was just waiting for CI to pass before taking a closer look. I'll do that next, but it may be a little while before I can find the time. Don't worry, I haven't forgotten about this. |
Sure, sounds good. Take the time you need and thanks for reviewing. Just want to make sure I've gotten everything done on my end, to avoid any "I am waiting on you, you wait on me" deadlock. :) |
Instead of doing e.g.
what if we did
This trick allows ASTs to be extensible, among other benefits.
I generally like this approach, but I had a specific problem in mind that would benefit which I would like to share. https://github.com/obsidiansystems/dombuilder-pandoc/blob/master/src/Reflex/Dom/Builder/Pandoc.hs is some code to translate the Pandoc AST to reflex-dom "dom builder action" order to use within a website built with reflex dom.
I would like to have my own custom handling of pandoc the pandoc AST --- e.g. parsing relative URLs in links into a Route AST --- without having to copy and paste that function. But if we do the above "functored AST" approach, I can replace
with
or
These can be thought of as specialized versions of
traverse_
orsequence_
, and they are very nice to work with!The text was updated successfully, but these errors were encountered: