The top Reddit example is tremendous. I'm passed being a Rust beginner, but I have a note to the Rust community: Your official examples are overcomplicated and bad and you should also feel a little bad. Stick to things like apple, orange, pear and you'll see much easier adoption than if you go with something like LendingIterator! Through the GAT process all I have seen is the same hyper-specific example used that con…
>Stick to things like apple, orange, pear While I am no pedagogical psychologist, I have witnessed mutiple times, how poor unrealistic examples give people a bad understanding of the thing they are trying to learn. Going with Apple, Orange, Pear would give people an idea of what the keywords did, but no understanding of when it was a good idea to apply the technique. I think that is one of the primary reasons OO suck…
Rust: “Explain GATs Like I'm 5 Years Old”
91–100 of 193 posts
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#92Re: Rust: “Explain GATs Like I'm 5 Years Old”
#93Because of that, programming languages should be designed to make the reading part as easy as possible.
What is the point of those high-level abstract features if they make reading/understanding the code too difficult?
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#94GAT is Generic Associated Types https://blog.rust-lang.org/2022/10/28/gats-stabilization.htm...
But until now I didn’t know what the letters stand for. Thank you.
Death to abbreviations!
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#95Re: Rust: “Explain GATs Like I'm 5 Years Old”
#96Earlier quoted context omitted.
I've yet to figure out why to use associated types instead of generic parameters, and every time I've seen an explanation I nod my head in confusion and carry on.
You can view generic parameters as "inputs", they are controlled by the consumer of the type/trait (you construct a `Vec ` because you want to store a bunch of `String` values). Associated types are "outputs", they are controlled by the impl (` as IntoIterator>::into_iter()` will always return a `std::vec::IntoIter `, because that is how the trait is implemented for `Vec `). You can often use generic parameters for "…
A: type level functions from types to (associated) types (i.e. normal generics)
B: type level functions from types to type level functions (either As or Bs) (GAT).
with generic parameters (i.e. higher kinded types, or template template parameters in C++) you could have type level functions that map type functions to (types or type functions), but once you have GATs you can fake them by passing to first order functions a type that has an associated type.
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#97I feel like they are making languages too complicated. Most projects should just be garbage collected, most don't need to deal with pointers or anything advanced. We need variables, functions, conditionals, loops, exception handling, struts, and a library with a bunch of standard utilities (including simple I/O and string managment). Everything else should be optional and kept out of sight unless you are looking for…
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#98Earlier quoted context omitted.
I think the easiest way to understand it is this: Suppose you have a concrete type like Vec Regular generics enable you to make the contained type generic, so you have: Vec where T can be i32, u32, String, etc. GATs allow you to make the container generic. So you can have: T where T might be Vec, Option, Box, etc.
Thanks, this was much easier to understand than the original article. What will I use this for? Usually for the “T” to be useful it needs to have some interface. In Java I’d just use Collection or something more abstract.
Not a Rust guy but I think that's the idea.
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#99The top Reddit example is tremendous. I'm passed being a Rust beginner, but I have a note to the Rust community: Your official examples are overcomplicated and bad and you should also feel a little bad. Stick to things like apple, orange, pear and you'll see much easier adoption than if you go with something like LendingIterator! Through the GAT process all I have seen is the same hyper-specific example used that con…
This means:
- they are not trivial no matter how much you bend it
- you should rarely use them in your day to day work (use as in "create traits with GATs")
- they allow you to abstract over certain things in a much nicer way. This thinks matter a lot for certain kinds of libraries. Which is why we do include them even through they are not simple (i.e. once some of the current limitations are lifted I expect there is a high chance for them to be used in the next major version of all of actix-web, axume, tower and a bunch of async libraries).
Through I agree that the example on the blog announcement and on reddit aren't grate. If GATs would just be for the problems described there adding them to the language wouldn't be worth it. (I mean adding a different more complicated and harder to use iterator trait which only matters for a small handful of use-cases really isn't enough reason to add such complicated language feature, on the other hand being able to abstract over async functions properly is a major boon).
Another problem is that some of the "better" examples currently can't be implemented in a straight forward way to the limitations which GATs still have for now.
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#100Earlier 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..