Hacker News new | past | comments | ask | show | jobs | submit login

    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.



I implemented basically this in Rust, and it was overwhelmingly rejected by the community at the time. People seem to like the strict typechecking.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: