As a beginner (having finished the book and not much more) the example in the top comment is very difficult to parse and hold in my head. At a glance I have no idea what we're doing and why.
More concretely, it's a pain to have to implement the same functions over and over for slightly different types, even when you're basically doing the same thing every time. Specifically, `Option` and `Result`, for example, both have `map` implemented for them (that's one lot of duplication), but also the consumers of the data structures need to know whether they've got an `Option` or a `Result` (and that's another lo…
Rust: “Explain GATs Like I'm 5 Years Old”
21–30 of 193 posts
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#22Rust better figure out quick how they can shut down the Haskell & C++ language artisans or it will be their downfall (in favor of something like Zig).
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#23Earlier quoted context omitted.
Rust getting more of Haskell's type system features is a good thing. The stronger your type system is, the more mistakes you can discover as compiler errors instead of runtime bugs.
> The stronger your type system is... I used to think a stronger and stronger type system was a universal good, then I got experience with code written by architecture astronauts[1] armed with such type systems. Knowing exactly which kinds of things to make impossible at compile time and which not is absolutely an art form. Unfortunately, such type systems seem to result in so many nightmares. https://www.joelonsoftw…
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#24Rust better figure out quick how they can shut down the Haskell & C++ language artisans or it will be their downfall (in favor of something like Zig).
- allows you to write these things with less effort
- is more expressive
I keep an eye on Nim as well. Their syntax for algebraic data types could use some syntactic sugar, but it looks like a powerful and fast language, and the syntax allows you to do away with all the c-style braces, curly braces and semicolons that pesters so many languages and gives me RSI.
More upsides I found: macros on the AST-level and fast compilation; it is a language that deserves more attention.
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#25I seriously doubt a 5 year old can understand this explanation.
I am over 30 and I don't understand the explanation. Probably because first and foremost I don't even know what a "GAT" or "GATs" are/is.
Explained in other terms, a generic is just a parameter for types, analogous to how `x` is a value parameter for the function call `foo(x)`.
Meanwhile, an associated type is just a type alias that's associated with a trait (a trait is a class, but with no state), similar to how traits can have associated functions (which are also known as "methods").
GATs, then, "just" let you use generics in associated types, which was previously unsupported in Rust.
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#26Rust better figure out quick how they can shut down the Haskell & C++ language artisans or it will be their downfall (in favor of something like Zig).
Zig still has to win the love of the giants that ship C++, and increasingly Rust, in their products.
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#27Earlier quoted context omitted.
Rust getting more of Haskell's type system features is a good thing. The stronger your type system is, the more mistakes you can discover as compiler errors instead of runtime bugs.
If a typesystem has any impact on the popularity of a language, then i assume rust doesn’t want to copy too much of haskell and needs to know where to stop..
As for Haskell, their motto is "avoid success at any cost" for a reason.
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#28Re: Rust: “Explain GATs Like I'm 5 Years Old”
#29Rust better figure out quick how they can shut down the Haskell & C++ language artisans or it will be their downfall (in favor of something like Zig).
Actually I find C++ concepts much easier to grasp than GATs. Zig still has to win the love of the giants that ship C++, and increasingly Rust, in their products.
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#30Rust better figure out quick how they can shut down the Haskell & C++ language artisans or it will be their downfall (in favor of something like Zig).