4 ms·
It feels like the part that's missing is the ability to abstract over these different types of function, polymorphically. At least, that seems to be where thing
by lmm 7y ago
It feels like the part that's missing is the ability to abstract over these different types of function, polymorphically. At least, that seems to be where things fall down when we try to talk about e.g. implementing a Functor trait in Rust.
As a concrete example, the `compose` method given should clearly be the same for `Fn`, `FnOnce`, and `FnMut`. Can we write it once and reuse it for `Fn`, `FnOnce` and `FnMut`? If not, why not?
- kccqzy 7y agoBecause Rust doesn't have higher-kinded types. Well it does but it doesn't allow you to define or implement traits for them. Also, what happens when you compose one function with FnMut and another with just Fn? The answer is clearly FnMut. These three traits are related by a subtyping relationship. I don't know enough Rust to answer the question of whether such a hypothetical compose function can return the right one from this hierarchy.