3 ms·
The downside is that you would have to put () (Rust's version of “nil”) in a bunch of functions to fulfil the requirements of the callback's signature since oth
by lihaoyi 14y ago
The downside is that you would have to put () (Rust's version of “nil”) in a bunch of functions to fulfil the requirements of the callback's signature since otherwise the type inferred from the function would be the value of the last expression
Wouldn't co/contra-variance solve this entirely? It works just fine in Scala for example
scala> def runTwice(f: () => Unit) = {
| f()
| f()
| }
runTwice: (f: () => Unit)Unit
scala> runTwice{ () =>
| println("moo")
| 1
| }
moo
moo
Note how it expects a function that returns Unit, i'm passing in a function that returns an Int (1), but the compiler is perfectly happy.
- pcwalton 14y agoI implemented basically this in Rust, and it was overwhelmingly rejected by the community at the time. People seem to like the strict typechecking.