Conversation

Has anyone ever made the case that a language with an sophisticated macro system gets even more benefit from a type system than a language w/o such a macro system (assuming one's macros are structured to take advantage of the static checks)?

I've been playing with a mini-DSL in Rust,, and it struck me how leveraging Rust's checks for exhaustiveness (in e.g. pattern matching the fields of a struct) allowed me to identify an incorrect macro invocation (where I had I left out one of the fields)

2
1
0

Of course one could argue that if my macro system were *really* expressive, it would be able to reflect on the static type declarations and validate my macro invocation before the expansion even occurred.

But that would require one being willing/able to implement those checks in one's macro.

The beauty of the approach I'm seeing here is that my macro's are pretty simple-minded rewriters (macro-by-example); the key is choosing to rewrite into code that maximizes the type system's static checks.

0
0
0
@pnkfelix I wrote a DSL for Rust where the selling point was not really the type system but the use of lifetimes to ensure correctness. Mostly because the "traits" it implemented could not really be described in Rust in a good way, so I could not use the type system as much in the way you describe. That is not to say that they type system is not a great help for writing the macros and finding issues.
0
1
2