-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Functor and Applicative #113
Conversation
|
||
pub trait Applicative<B, F>: Functor<B> + Kind<F> + Sized | ||
where F: Fn(Self::Item) -> B { | ||
fn pure_(Self::Item) -> Self; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yuck on the hack for avoiding the keyword. I might suggest looking to other langauges for naming precedent. (I know a lot of JS libs call this of
; I don't know about other languages)
ISTM you are also going to immediately run into problems with type inference when you try to use this method, because its signature does not constrain F
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also seen just
being used in the wild.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some "insider info": pure
will likely be removed as a keyword soon-ish.
For now, I'm partial to pointed
or wrap
.
I think this really needs examples of usage to demonstrate that it is useful. Or rather, usable. Unsurprisingly, 99% of my own attempts to encode HKT-like abstractions into rust only seemed like a good idea up until the point that I actually tried to use them. From past experience with type level programming in rust, I doubt it is possible to get very far at all with having the element type be a type argument of In summary: I don't think the language is ready for this. |
My view is that we'd like to experiment with this once GATs land, so I agree with @ExpHP. |
Another heads up: given that Rust has affine typing and that we have See also the following blog post on linear monads in Haskell: https://m0ar.github.io/safe-streaming/2017/07/20/homegrown-linear-monads.html |
FWIW, I think this is a really cool attempt at implementing HKTs 😎 The Just for comparisons' sake:
I believe both of these are based on the Lightweight HKTs paper that showed how to emulate HKTs in OCaml. Having said that, I think @ExpHP is right; this would be a lot nicer if you showed usage (e.g. tests or doctests) so it would be easier to see how this works out in practice :) |
type ForOption = Option<()>; 🦆 |
Triage: shall we close this in wait of GATs? |
Yeah, regrettably, I think it might be best to wait for GATs (which actually shouldn't be all that far off ?? (rust-lang/chalk#116) |
No problem |
GAT is finally here after a long wait! 🍾 Time to reconsider this one? |
Ah, I see, so they've been stabilized on nightly. That's good news! I wouldn't exactly say that they're "here" yet (IIRC the So yeah, if people want to experiment with this and make PRs, I'd say go right ahead. |
This works on stable, but is ugly