Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add the ability to quote code as an abstract syntax tree #682
Add the ability to quote code as an abstract syntax tree
I propose we add the ability to quote code as an abstract syntax tree.
A new operator pair could be introduced that would allow fragments of F# code to be quoted as actual F#, perhaps
The resulting code being an ast fragment like this:
The existing way of approaching this problem in F# is to use quotations along with type providers which is too limited and also lacks the ability to represent the F# language without a loss of information, see #680 / #681 for two such issues.
Pros and Cons
The advantages of making this adjustment to F# are a vast improvement to F# meta programming capability, the compilers API (FCS) already takes an abstract syntax tree as input so this is increasing the usage of that capability.
The disadvantages of making this adjustment to F# are the time taken to do the work, the added complexity to the language.
Estimated cost (M/L):
Related suggestions: (put links to related suggestions here)
Please tick this by placing a cross in the box:
Please tick all that apply:
Take a look at OCaml PPX for inspiration: http://ocamllabs.io/doc/ppx.html
Metaprogramming should also come with production quality staging support, to support real-world industrial usage (~the performance story). Please learn from the type provider (TP) story, even if it's a good idea the real-world industrial usage matters a lot - as far as I know industrial users mostly avoid TP because it makes their life lot harder in real-world (unpredictability, performance issues, weird errors, etc).
Tiark Rompf: Abstraction without regret:
We can currently do parts of what PPX can do, what I would like is better integration into the compiler chain like adding quoted literals, splicing etc. I have a program now which does what
I wanted this language suggestion to act as a starting point for a discussion on that, I didn't want to describe anything too deeply incase this suggestion gets closed.
I would love to have more metaprogramming story for F#. And at the end to have language level integration - something like Lightweight Modular Staging for Scala.
It seems that some kind of code specialization and partial staging would be possible with your proposal, am I right? Would it be possible to also control when the ast transformation should happen eg.: runtime / compilation time?
The first step is to allow the quoting of code to ast fragments, after that holes could be defined and other fragments could be spliced into place, I would propose that this all happens at compile time.
Finally there could be an integration of quoted fragment so that the staged ast quotation is incorporated with the current one during compilation.
Adding shouldn’t really be an issue. Modifying might be, though
On Fri, Jul 27, 2018, at 09:04, Dave Thomas wrote: Any new feature alters the AST, like Span added to the AST recently.> — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
Just commenting on the above:
This is not the case - some people certainly run into problems using TPs, but I consistently meet many people who use them in production scenarios. Those who run into problems are much more vocal of course.
The same is true of F# quotations, or Rosyln analyzers... Indeed OCaml meta-programming has/had many issues and I saw many examples of them being used/unused. I actually think all meta-programming solutions have problems like this: they solve various kinds of problems but are frequently misused or run into tooling issues