Live data from Hacker News

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

old.reddit.com

11–20 of 193 posts

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

#11
Is there any way to use GATs to achieve a particular use case of ah-hoc/anonymous enums[0]? Say if library L1 returns enum A|B, L2 operates on enum A|B, and main wants to pass enum A|B from L1 to L2, with the kicker being A, B are concrete in main.

I'm not interested in distinguishing between multiple appearances of the same type as in the RFC example, so rather like:

  let foo: (~str|int) = (_|666);
  match foo {
    (s: str|_) => println(fmt!("string: %?", s)),
    (_|n: int) => println(fmt!("int: %?", n))
  }
The most disappointing thing I've encountered with Rust is not seeing anonymous enums or structural typing other than for tuples. I read somewhere that structural typing is only for tuples because the word struct is in structural(?!).

[0] https://github.com/rust-lang/rfcs/issues/294

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

#12

I seriously doubt a 5 year old can understand this explanation.

There's another (better) example down in the comments using a PointerFamily trait; someone asked "ELI4" and the answer is pretty good:

https://old.reddit.com/r/rust/comments/ynvm8a/could_someone_...

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

#14
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).

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.

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

#18
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).

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

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

#20
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).

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.joelonsoftware.com/2001/04/21/dont-let-architect...

Post reply on HN