Nice to see Haskell people helping to make rust be the best language it can be.
Conversation
This is all based on my Racket experience, not Haskell! Haskell doesn’t have hygienic macros (and really I don’t believe it has macros at all).
2
8
Cool! Do you like scala's new macro system? I've heard good things about it.
1
tbh, I’ve gotten this question a number of times over the past ~6 years, and every time I’m unsure whether they’re referring to some new macro system I’m as-yet-unaware of or if it’s the one I know about, as they’ve gone through several already. do you have a documentation link?
1
2
I believe it supports a number of approaches, `inline`, MetaML-style staged macros with cross-stage persistence, and compile-time and runtime staging:
- docs.scala-lang.org/scala3/guides/
- docs.scala-lang.org/scala3/referen
1
Not sure to what extent it also supports ‘untyped’ macros like in Rust and Scheme etc. I do remember seeing a paper on doing this in the context of Scala, but I don't know if it made it into Scala 3, or whether it remains part of a third-party framework: dl.acm.org/doi/10.1145/31
1
1
Yes, I would not really call any of these things a “macro system”, personally. They are much closer to staging systems or Template Haskell than Lisp/Rust macros. The problem with all these systems is that they only allow quotation of fixed syntactic classes, like exprs/types.
2
1
1
The whole *concept* behind a macro system, in my mind, is that it allows you to extend those syntactic classes. Both Lisp and Rust make this possible by only parsing a minimal tree structure that provides grouping, then letting macro code do the actual *parsing*.
1
1
5
This is why the R in REPL is “read”, not “parse”. Reading an s-expression does not parse a Lisp program in any sense—it just gives you its grouping structure. The mechanism by which you parse a Lisp program is macroexpansion. Each form in the language is associated with a parser.
3
8
Giving the programmer `quote` and `splice` operators is interesting, but it doesn’t really let you do virtually any of the things people write Racket macros to do, because those macros have their own grammar and scoping rules. So I think calling these “macros” is just confusing.
1
4
Thanks! Viewing macros as allowing you to “extend those syntactic classes” is a helpful way to look at it. I still think staged programming is really interesting for code generation, but you're right that they don't cover all the things you want out of a macro system.


