News for hackers. Stuff that matters.
Re:How I went about learning Rust by nicoburns on Friday July 15, 2022 @06:53AM (#32106817)
Arguably dynamic languages have sum types: every variable is one big sum type with the variants being every other type! I suspect the lack of sum types in many static languages are partially responsible for the popularity of dynamic ones.
Re:How I went about learning Rust by kortex on Friday July 15, 2022 @12:02PM (#32109505)
> I suspect the lack of sum types in many static languages are partially responsible for the popularity of dynamic ones.

I can totally see this. I started writing a small cli tool in Go, and despite knowing way less Rust, I switched to it and was able to make a lot better progress at first due to pattern matching and result types. It was just so much easier/more ergonomic to write a simple parser.

The Go code was a mishmash of ugly structs and tons of null checking and special casing.

Re:How I went about learning Rust by estebank on Friday July 15, 2022 @11:19PM (#32114949)
I would say that traits are a better analogy for dynamic types, but at the same time you can think of enums as closed sets and traits as open sets, so they are different ways of encoding sets of possible structure and functionality, more alike in what they provide than it initially seems.
Re:How I went about learning Rust by int_19h on Friday July 15, 2022 @04:30PM (#32112441)
Some statically typed languages have union types that are extensible in a similar fashion; e.g. in OCaml:

https://v2.ocaml.org/manual/polyvariant.html

Re:How I went about learning Rust by davidatbu on Friday July 15, 2022 @08:55AM (#32107628)
Very interesting perspective!