Live data from Hacker News

Monads and GATs in Nightly Rust

fpcomplete.com

11–20 of 176 posts

Re: Monads and GATs in Nightly Rust

#11

It seems that Rust just keeps getting more and more features. Do people generally feel like the more features the better the language? I'm personally of the opinion that less is more. Is this a pain point at the moment for Rust devs? Do you feel like the code you write is the same code 99% of other Rust developers would write to solve the same problem? Or is there actually a really large variety of styles?

Rust hasn't fundamentally changed all that much in the end, the only notable exception being `async`, and I feel like that's a pretty big success so far, being used far and wide from web servers to embedded task scheduling.

I do not currently feel like there are many different solutions to a problem - at least, not in the sense that the solutions only differ by style. Of course each problems have different solutions that are different points in the performance spectrum (static vs dynamic dispatch, etc...).

All the big features that are coming (GAT, const generics), all feel like lifting restrictions that will remove the need for hacks. To take const generics as an example, it will obsolete the need for `typenum` and `generic-array`, giving us a more consistent style. Less type-hacking is a good thing.

I do agree with the sentiment: Rust is already a big language, and has to be careful when weighting new language features to make sure they don't spend too much mental overhead. So far, I feel like they've done a good job at it.

Re: Monads and GATs in Nightly Rust

#12
post #2

Side question : Is there any example of a language that has successfully added HKT after it was released and became popular ?

I'd say no, given that no language with HKT has ever been popular (sorry Haskell, you're cool, but not “popular”)…

I was going to object, but in doing my own research I found that Haskell ranked even below Dart in the SO Developer Survey for languages in use - and I certainly wouldn't consider Dart popular, since I've never seen, let alone met, anyone using it.

That said, "popular" is a very contextual term. Within certain classes of programmers (and I don't mean the obvious tautological one) Haskell is extremely popular, and fit for purpose. I assume the same is true for Dart.

And I would add that, in those circles, the introduction of advanced HKT features like RankNTypes has been extremely successful.

Re: Monads and GATs in Nightly Rust

#13

It seems that Rust just keeps getting more and more features. Do people generally feel like the more features the better the language? I'm personally of the opinion that less is more. Is this a pain point at the moment for Rust devs? Do you feel like the code you write is the same code 99% of other Rust developers would write to solve the same problem? Or is there actually a really large variety of styles?

Rust is indeed starting to enter the territory where features are added on top of features as a way to deal with that there were too many restrictions at the start.

It is starting to become a pain to me, but I'm glad that apparently there is some semblance of h.k.t.'s now, which was very much wanted.

Re: Monads and GATs in Nightly Rust

#15

How does one get familiar with these kind meta programming concepts. Is there some kind bible or series one can read to get up to speed?

Im a Scala fan, so all these will be focused around Scala, but they will teach you about Monad and Category Theory.

I would start with http://learnyouahaskell.com - Its Haskell based but it covers them pretty well.

Otherwise I use https://typelevel.org/cats/ for Scala daily and they have an _ok_ guide. But the best guide I've found for it was http://eed3si9n.com/herding-cats/

Re: Monads and GATs in Nightly Rust

#16
post #7

It seems that Rust just keeps getting more and more features. Do people generally feel like the more features the better the language? I'm personally of the opinion that less is more. Is this a pain point at the moment for Rust devs? Do you feel like the code you write is the same code 99% of other Rust developers would write to solve the same problem? Or is there actually a really large variety of styles?

I'm not sure you can only see this in the light of 'more features'. From a more fundamental perspective GATs just lift a restriction. Rust already has generics and Rust already has associated types. Previously you needed to know/remember those features cannot interact for some reason, now they can. To me this is in a sense 'less' and not 'more'. So, a matter of perspective I guess.

But why have associated types in the first place since they have the same expressive power as generics? https://stackoverflow.com/questions/33647337/what-is-the-dif...

Re: Monads and GATs in Nightly Rust

#17

Earlier quoted context omitted.

I'd say no, given that no language with HKT has ever been popular (sorry Haskell, you're cool, but not “popular”)…

I was going to object, but in doing my own research I found that Haskell ranked even below Dart in the SO Developer Survey for languages in use - and I certainly wouldn't consider Dart popular, since I've never seen, let alone met, anyone using it. That said, "popular" is a very contextual term. Within certain classes of programmers (and I don't mean the obvious tautological one) Haskell is extremely popular, and fit…

Dart is seeing a bit of interest thanks to Flutter, the cross-platform UI toolkit.

Re: Monads and GATs in Nightly Rust

#18
Does anybody know if GATs would enable to issue indexes/handles tied to a container without the use of closures? This would allow compile-time checks that indexes are only used with their container.

The most advanced crate for such use-case is `indexing` [0] but it is pretty complex inside, requires closures and seems more like an experiment.

[0]: https://github.com/bluss/indexing

Re: Monads and GATs in Nightly Rust

#19
post #2

Side question : Is there any example of a language that has successfully added HKT after it was released and became popular ?

I'd say no, given that no language with HKT has ever been popular (sorry Haskell, you're cool, but not “popular”)…

template template parameters and nested template classes work as HKT in C++ in practice (and are extensively used for exactly that purpose), and I think C++ counts as a popular language.

Re: Monads and GATs in Nightly Rust

#20

Does anybody know if GATs would enable to issue indexes/handles tied to a container without the use of closures? This would allow compile-time checks that indexes are only used with their container. The most advanced crate for such use-case is `indexing` [0] but it is pretty complex inside, requires closures and seems more like an experiment. [0]: https://github.com/bluss/indexing

In principle, the ingredient you need for that use case is "existential types". I suspect GATs let you define existential types -- after all, the selling point is that the trait defines some type, and you can't rely on what type any particular implementor chooses. (But I can't quite put my finger on why non-G associated types shouldn't be enough.)

In Java(!), I have a class `Database` whose constructor is private and whose sole static factory returns `Database`. Thus, the caller must assume that every instance they create is parameterized over a distinct unknown type -- even if, in the implementation, $Database = Object. The dollar-sign prefix is a hint to the reader that this type parameter is meant to be a type correlated with a unique value.

You can get an `Index` from any database, and it's parametrized over the owning database's unique existential type. Indexes over two different databases can't be confused.

The only issue (so far) is that you have to be careful not to "forget" the correlation between the type parameters on an index and its owning database. If the type parameter decays back into a wildcard, the correlation is lost.

[1] https://varkor.github.io/blog/2018/07/03/existential-types-i...

Post reply on HN