Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with type inference #4124

Closed
stevej opened this issue Dec 6, 2012 · 3 comments
Closed

Problem with type inference #4124

stevej opened this issue Dec 6, 2012 · 3 comments

Comments

@stevej
Copy link

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.

https://gist.github.com/4221872

This is with rustc 0.4

Thanks!

@catamorphism
Copy link
Contributor

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
Copy link
Author

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 as completed Dec 6, 2012
@catamorphism
Copy link
Contributor

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!

calebcartwright pushed a commit to calebcartwright/rust that referenced this issue Dec 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants