Open HugoPeters1024 opened 2 years ago
Nice! Although this isn't quite proper higher kinded types, it's not truly parametric in B. Good news is that people are working on it, if you look at the TODO list, it seems it's coming soon!
Completely unrelated sidenote: if you like this sort of hackery, I've always wanted to try something but never had the time: I'm conjecturing that with async Rust where async Futures are Clone, we could implement monadic do notation using the mother of all monads idea. Could be a fun project
@exFalso Nice! Although this isn't quite proper higher kinded types, it's not truly parametric in B. Good news is that people are working on it, if you look at the TODO list, it seems it's coming soon!
Completely unrelated sidenote: if you like this sort of hackery, I've always wanted to try something but never had the time: I'm conjecturing that with async Rust where async Futures are Clone, we could implement monadic do notation using the mother of all monads idea. Could be a fun project
Thanks for you comment! What exactly do you mean with it being not truly parametric in B? Regarding the mother of all monads, that's a cool concept. Too bad that the IO-pandora box has already been opened for rust :)
Interesting read, thanks.
Small typo: the associated type in the declaration of Generic1
is named R
, should be I
.
@pchampin Interesting read, thanks. Small typo: the associated type in the declaration of
Generic1
is namedR
, should beI
.
Thanks for the kind words, typo is fixed :)
@HugoPeters1024
@exFalso Nice! Although this isn't quite proper higher kinded types, it's not truly parametric in B. Good news is that people are working on it, if you look at the TODO list, it seems it's coming soon!
Completely unrelated sidenote: if you like this sort of hackery, I've always wanted to try something but never had the time: I'm conjecturing that with async Rust where async Futures are Clone, we could implement monadic do notation using the mother of all monads idea. Could be a fun project
Thanks for you comment! What exactly do you mean with it being not truly parametric in B? Regarding the mother of all monads, that's a cool concept. Too bad that the IO-pandora box has already been opened for rust :)
Ah my bad, didn't see the Plug action, thought B is bound by a Functor associated type. Yeah this works, sweet!
Copied all the code into this playground for easy viewing and play.
Made two changes: 1) switch from println! to dbg! which I feel is cleaner, 2) use .to_string()
@Cypher1 Copied all the code into this playground for easy viewing and play.
Made two changes: 1) switch from println! to dbg! which I feel is cleaner, 2) use
.to_string()
Thanks for your suggestions! Especially the .to_string()
method is something I will use from now on
For Functor, why does this not work?
trait Functor {
fn fmap<B, F: Fn(&<Self as Generic1>::I) -> B>(&self, f: &F) -> <Self as Plug<B>>::R
where Self: Plug<B> + Generic1;
}
or similarly:
trait Functor {
fn fmap<B>(&self, f: &fn(&<Self as Generic1>::I) -> B>) -> <Self as Plug<B>>::R
where Self: Plug<B> + Generic1;
}
Why is dyn
required in this case?
I also messed around and looks like the following works (though it is less powerful type-wise)
trait Functor<B>: Plug<B> + Generic1 {
fn fmap(&self, f: &fn(&<Self as Generic1>::I) -> B>) -> <Self as Plug<B>>::R;
}
https://hugopeters.me/posts/14/