4 ms·
We do! We've been pretty quietly developing it, but right now, the Rust compiler contains a full interpreter as well, specifically to do compile-time evaluation
by steveklabnik 8y ago
We do! We've been pretty quietly developing it, but right now, the Rust compiler contains a full interpreter as well, specifically to do compile-time evaluation. But, we also do not want to have unlimited compile-time facilities, as that has serious soundness problems. "const fn" is the name of the user-facing feature, and MIRI is the underlying interpreter, if you want to do some searching.
That said, that work tends to fall under "compile time expressions"; "template templates" are more likely to be served by some sort of eventual HKT, or maybe even by ATC. I always forget what perfect forwarding is so I probably shouldn't comment on it.
I am willing to bet that this stuff is a major part of next year's roadmap, but we'll see!
- Sharlin 8y agoFor the uninitiated, HKT means higher kinded types, which is the type theoretic term for what C++ calls template template parameters. That is, the possibility to pass around type-level functions. I don't know what ATC refers to.
- steveklabnik 8y agoYes, thank you! ATC is "associated type constructors". I believe Haskell calls them "type families"? It's sort of a similar idea; a form of higher-kindness. We are likely to get ATC in the medium term, but full HKT is farther out.
- Sharlin 8y agoRight, thanks! It sounded familiar but google revealed nothing. Should have tried "atc rust".
- deleted 8y ago[deleted]
- senorsmile 8y agoThere's a ticket about this. The linked comment in particular gives a good background on what HKT's are, and how they could look in Rust: https://github.com/rust-lang/rfcs/issues/324#issuecomment-248779799 https://github.com/rust-lang/rfcs/issues/324#issuecomment-24...
- mamcx 8y agoI wish the macro system was more ergonomic, like this: fn %identifier(value:%type) -> %type { BytesMut::from(value) } ie, to look like html templates like handlebars or similar.
- steveklabnik 8y agoProcedural macros can have this, in a sense; see this crate: https://crates.io/crates/quote https://crates.io/crates/quote
- baby 8y agoI have a question about that actually, macros in C/C++ are disgusting, why isn't Rust trying to improve it? It's better obviously but it is still not a nice thing to parse.
- steveklabnik 8y agoRust macros are almost nothing like C or C++ macros; they operate on an AST, not on the literal text.
- baby 8y agoI'm talking of the syntax. Why can't I write a macro in more rust-like form for example instead of a very different language
- steveklabnik 8y agoWell, patterns are a very different language than rust; rust has no way to express “one or more of this thing” for example. I wasn’t involved when the syntax was chosen, and that was well before our RFC process, so I don’t have any real, deep explanation for you, sorry!
- mamcx 8y agoIn fact thinking about the same, and because I'm building a toy language, a macro system could look like: https://elixir-lang.org/getting-started/meta/macros.html https://elixir-lang.org/getting-started/meta/macros.html