Problem with type inference #4124

stevej opened this Issue Dec 6, 2012 · 3 comments


None yet
2 participants

stevej commented Dec 6, 2012

I wrote up a simple, naive implementation of thunks in Rust but I've been having trouble compiling a test example, inference is unifying to () and I'm not able to fill in a type parameter to override this.

It's a small example so I threw it in a gist.

This is with rustc 0.4



catamorphism commented Dec 6, 2012

As written, your thunk evaluates the value of a + 10 and then throws it away, returning (). What you probably want instead is:

let thunk = Lazy (|| {
    a + 10

Let us know if that solves the problem!

stevej commented Dec 6, 2012

Oh wow, I didn't realize there was such a huge difference between using or not using a semi-colon. I've now moved on to new issues with this program related to copying non-copyable values. Thanks!

@stevej stevej closed this Dec 6, 2012


catamorphism commented Dec 6, 2012

Yeah, it's a common source of confusion: the meaning of the semicolon is always "Take this expression and turn it into a new statement, with result type (), that just evaluates the expression for its side-effects". Glad that helped!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment