5 ms·
Rust seems to be good for language designers thanks to a combination of features - enums that can contain data (aka tagged unions) and exhaustive matching on al
by nindalf 3y ago
Rust seems to be good for language designers thanks to a combination of features - enums that can contain data (aka tagged unions) and exhaustive matching on all variants of that enum with the match statement. This makes it easy to model all the token types of the language. Good performance helps as well.
I reckon other languages could replicate this combination, it’s not very hard. Dart added this feature recently. I just don’t know why it’s taken so long for tagged unions + exhaustive match to become widely adopted.
- Jeff_Brown 3y agoExhaustive pattern matching and tagged unions (sum types) are both great. Haskell's had them since its inception.
- JoelMcCracken 3y agowell, sadly, you have to turn on an option to get exhaustivity checking. Which annoys me, because sometimes I forget to turn it on for a small project/script. I need to come up with a haskell "new project" template thing
- carterschonwald 3y agoWall!it’s great.
- Jeff_Brown 3y ago[A clarification to the less familiar: --Wall is a compiler option that stands for "all warnings".]
- carterschonwald 3y agoAnd in ghc is enables coverage checking for pattern matching. The most amazing compiler feature in most compilers Thx for expositing my remark :)
- vmchale 3y agoI prefer having a GC, makes things easier. Also a copying GC can be better for some of the stuff you do in a compiler (immutable data structures).
- smaddox 3y agoEasier for quick prototypes, for sure (although I switched to Rust from Haskell due to even worse compile times in Haskell and my disdain for monad transformers). Also, Rust can't currently do nested pattern matching through Boxes, which can be annoying, coming from Haskell. But for a high performance compiler, manually managed arena allocation will beat out a generational GC.
- discardable_dan 3y agoChez Scheme would disagree.
- smaddox 3y agoHow so?
- phibz 3y agobox_patterns exists on unstable. Unfortunately it's still not merged.
- linkdd 3y ago> Rust seems to be good for language designers thanks to a combination of features Not only the type system is quite nice, the ecosystem is full of nice crates: - lexing: logos - parsers: rust-peg / lalrpop / nom - utilities: string-interner / linecol / snailquote I also wrote about this here: https://david-delassus.medium.com/writing-a-simple-lisp-interpreter-in-rust-91dd32ea4d8f?sk=e3b513bd85e9d9d944180ec35d96dbcf https://david-delassus.medium.com/writing-a-simple-lisp-inte... (friend link, no paywall)
- xcdzvyn 3y agoI came cross this post when I was working on my own LISP parser :) Very cool Though personally I think writing LISP interpreters with parser libraries should be considered sacrilege
- linkdd 3y ago> Though personally I think writing LISP interpreters with parser libraries should be considered sacrilege Agreed, though the point of the article was to explore the Rust ecosystem. When learning, a little bit of blasphemy isn't a bad thing :)
- brundolf 3y agoRust's enums/matching come from its ML lineage (OCaml, etc), and that family of languages has strong roots in programming language work ("ML" stands for "Meta Language"), so it makes sense!