10

Rust does type inference based on stuff I do later down in the code. Like wtf? That's cool

Comments
  • 1
    This is the way
  • 1
    Oh dang, this is heaven experience!
  • 4
    Yep, that is the gift of proper static analysis. OCaml does that too.
  • 2
    It's pretty standard at the low low price of not having very extensive implicit casts.
  • 1
    @lorentz What do you mean by extensive implicit casts?
  • 1
    I say pretty standard but I failed miserably at Hindley-Milner type inference. It's fucking cool, I agree.
  • 2
    @ScriptCoded Implicit casts don't stack well with HM, or any kind of reversible type inference. Rust has very basic implicit casts, everything else is explicit.
  • 1
    @ScriptCoded

    Like you can't do stuff like

    float f = 10

    You need to do

    float f = 10.0

    And you also usually have other stuff, like, for example, Ocaml:

    - doesnt allow adding int and float
    - has a separate operator for float addition (+ is for int, +. is for float)
    - doesn't allow overloading operators or functions

    Rust is similar although I don't know all the details.

    The reason is that the compiler needs to be able to figure out the types based on the usage, and if you have too many places where the type could be different, the compiler has trouble.
  • 0
    @lorentz Ah that explains it, always wondered why not even int widening is implicit
Add Comment