3 ms·
Thanks lalaithion! I don’t know Rust, so it’s interesting to see how different it is compared to Haskell. A question: how much of this would actually compile i
by bradrn 5y ago
Thanks lalaithion! I don’t know Rust, so it’s interesting to see how different it is compared to Haskell.
A question: how much of this would actually compile in Rust?
- deleted 5y ago[deleted]
- kaoD 5y ago- Assuming `Int` and `Bool` are user-defined types (Rust has `bool` and many types of ints like `usize`, `i64`, etc. instead). If you want to work over ANY primitive integer you can use the `num_traits` crate and make your type generic over `num_traits::PrimInt`, or even `num_integer::Integer` to include support for crates such as `num_bigint`. - Rust needs indirection for recursive data types (like the AST) using `Box`, references, or another kind of indirection. Otherwise, the size isn't known at compile time (since it's potentially infinite). - Rust doesn't have GADTs (yet?) so the last AST is purely theoretical. - `IgnoreTheType` (and `AST<R>`) would require explicit use of `PhantomData` for variants without `R` https://doc.rust-lang.org/std/marker/struct.PhantomData.html https://doc.rust-lang.org/std/marker/struct.PhantomData.html On Rust's playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=40b9ce0351c3adccd53cc6231c72d742 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- bradrn 5y agoThank you! So it looks like most of my post does indeed work, except for the GADT itself. (Also, I had not known about Rust Playground, so thanks for introducing me to that too.)