Open
Description
Given the following code: play
fn rec_clone<'a>(v: &'a str, rec: &dyn Fn(&'a str) -> String) -> String {
todo!()
}
pub fn clone() -> impl Fn(&str) -> String {
fix::<&str, String>(rec_clone)
}
// https://stackoverflow.com/a/42182841
fn fix<A, B>(func: fn(A, &dyn Fn(A) -> B) -> B) -> impl Fn(A) -> B {
move |val: A| func(val, &fix(func))
}
The current output is:
error[E0308]: mismatched types
--> src/lib.rs:5:19
|
5 | pub fn clone() -> impl Fn(&str) -> String {
| ^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
...
10 | fn fix<A, B>(func: fn(A, &dyn Fn(A) -> B) -> B) -> impl Fn(A) -> B {
| ---------------
| |
| the expected opaque type
| the found opaque type
|
= note: expected associated type `<impl Fn(&str)-> String as FnOnce<(&str,)>>::Output`
found associated type `<impl Fn(&str)-> String as FnOnce<(&str,)>>::Output`
It's irritating that expected and found are the same. Also "one type is more general than the other" could give an explanation why one is more general (like, what parameter). And, I don't know how FnOnce::Output
is relevant.
One more thing: When you delete the return type from the signature of clone, it says expected unit type `()` found opaque type `impl Fn(&Fix<FC>)-> Fix<FC>`
, which when implemented, doesn't work.