You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am going through the Category Theory For Programmers book and am writing quite obscure code. I defined a memorize function but, as usual, didn't yet know how I'd like to implement it and opted to insert a todo! for the time being. This was the first time I came across the todo! macro in the body of a function, which I thought was a valid return type for all functions,
which produced a compilation error.
I expected the program to successfully compile, but instead I received the following compilation error:
error[E0277]: expected a `Fn<(V,)>` closure, found `()`
--> src/lib.rs:1:41
|
1 | fn memoize<V, R>(f: impl Fn(V) -> R) -> impl Fn(V) -> R {
| ^^^^^^^^^^^^^^^ expected an `Fn<(V,)>` closure, found `()`
|
= help: the trait `Fn<(V,)>` is not implemented for `()`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: could not compile `catagory-theory-rust`
To learn more, run the command again with --verbose.
The more interesting part is that the function does compile successfully when you return it's input argument:
fnmemoize<V,R>(f:implFn(V) -> R) -> implFn(V) -> R{
f
}
This makes me think that there is some weird interaction between the panic! macro and the type checker or something.
Meta
Tried on both the latest stable and nightly versions. Both produce the same output.
rustc --version --verbose:
> rustc -V
rustc 1.52.1 (9bc8c42bb 2021-05-09)
The text was updated successfully, but these errors were encountered:
I am going through the Category Theory For Programmers book and am writing quite obscure code. I defined a memorize function but, as usual, didn't yet know how I'd like to implement it and opted to insert a
todo!
for the time being. This was the first time I came across thetodo!
macro in the body of a function, which I thought was a valid return type for all functions,which produced a compilation error.
I tried this code:
and even:
I expected the program to successfully compile, but instead I received the following compilation error:
The more interesting part is that the function does compile successfully when you return it's input argument:
This makes me think that there is some weird interaction between the
panic!
macro and the type checker or something.Meta
Tried on both the latest
stable
andnightly
versions. Both produce the same output.rustc --version --verbose
:The text was updated successfully, but these errors were encountered: