Live data from Hacker News

Rust: “Explain GATs Like I'm 5 Years Old”

old.reddit.com

21–30 of 193 posts

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#21
post #7
post #2

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…

Result and Option both implement Try, so if you actually just want to know whether to keep going or give up, the Try trait will give you a ControlFlow which says exactly that regardless of whether your input is an Option or a Result

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#22
post #10

Rust 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).

Well, it's not academic, it solves real problems. More so for library developers than for application developers, but a thriving and great ecosystem of libraries is also good for application developers.

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#23
post #20

Earlier 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…

at the end of the day architecture astronauts delegate pipe laying to plumbers, and the plumbers benefit from existing build plans created by architects with all their sophisticated tooling.

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#24
post #10

Rust 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).

Well, in this realm Haskell

- 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”

#25

I 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.

"Generic Associated Type".

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”

#26
post #10

Rust 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”

#27
post #18

Earlier 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..

Typescript.

As for Haskell, their motto is "avoid success at any cost" for a reason.

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#28
I'm filing this one along with Monads and Haskell as programming concepts that I'll never understand. Rust is my favorite language, but that explanation, lauded directly below it as This is personally the easiest to understand example I've seen of GATs., was incomprehensible.

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#29
post #26
post #10

Rust 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.

Aren't GATs equivalent to nested template classes? I.e. they are really orthogonal to concepts.

Re: Rust: “Explain GATs Like I'm 5 Years Old”

#30
post #10

Rust 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).

GATs are an essential part of Rust's long-term async/await story. It's not language-wankery, this is driven by actual real-world use cases. Rust's own stdlib would have benefited from this in many places had this feature existed years ago.
Post reply on HN