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

Why is the ... as ... part needed to evaluate property functions? #216

Closed
mcandre opened this issue Oct 28, 2018 · 3 comments
Closed

Why is the ... as ... part needed to evaluate property functions? #216

mcandre opened this issue Oct 28, 2018 · 3 comments

Comments

@mcandre
Copy link

mcandre commented Oct 28, 2018

Curious, why do I need to remind the compiler that my fn (seed : usize, password : String) -> bool { ... } is a fn(usize, String) -> bool with the as token when I pass this function to quickcheck::quickcheck()?

As a workaround, I am declaring my properties as lambdas variables, explicitly typed to their signatures. But I would prefer not to have to do this.

@BurntSushi
Copy link
Owner

Nobody would prefer to do this. I think this requirement was introduced here by making each fn item have its own distinct type: rust-lang/rust#19891

There is already an issue tracking this problem for quickcheck, and in particular, we would like to be ablw to use closures for property functions: #56

The quickcheck macro is meant to alleviate this annoyance in some cases.

@DestyNova
Copy link

Hi @BurntSushi -- I'm just a beginner with Rust but I'm struggling to understand what the benefit of that "unique type per fn item" PR was. We can see the downside of it is lots of extra as fn(...) -> ... annotations in heavily functional code, but there must have been some good reason to do it that outweighed the noise?

@BurntSushi
Copy link
Owner

That PR was from 6 years ago. I don't have any context on it now. FWIW, I've only ever run into this problem with quickcheck specifically. I do not think it is endemic to "heavily functional" code.

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

3 participants