Hacker News new | comments | ask | show | jobs | submit login

Rust was the first language in which I used tagged unions. While I can't say that I use Rust at the moment (not mature enough and too low-level for my current needs), I found pattern matching and tagged unions so beneficial and practical that now I refuse to use any language that doesn't have them. Currently I'm writing a bunch of code in F#.

I don't know what the language of the future will be but I can't imagine it not having an ML heritage.




ML-style pattern matching is neat. There's actually an entire formal logic of computation oriented around it called the pattern calculus, though it's still in relatively early research.

That said, the language with the most powerful pattern matching engine I've used so far has been Erlang. Just about everything there is intimately tied to it, giving it a homoiconicity between the code and the literal data types. You can even pattern match on binary formats, like file headers or packet structures.

It seems like Algol-like languages are slowly absorbing lessons from ML. Rust is quite an evident example.


I needed to write a small AST in Java, and I actually had to write the definition in ML on a sheet of paper to see how to do it. It's so weird that so many languages don't have sum types.


What's too bad is that Java had a chance to handle alternatives properly as sum types, when enums were being added. But the designers chose instead of sum types, to add them as yet another kind of "object" that have to have a common constructor (and thus the exact same backing data) and methods. So basically all the variants have to be of the same "shape". Very disappointing!


This has been my experience with Rust as well. Came for the C/C++ competitor, stayed for the type system. Also not using it for anything "real" yet, but excited to at some point.




Applications are open for YC Summer 2019

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: