Giter Site home page Giter Site logo

Comments (13)

BurntSushi avatar BurntSushi commented on August 11, 2024 1

Errm, try: quickcheck(prop as fn(Vec<i32>) -> bool).

from quickcheck.

BurntSushi avatar BurntSushi commented on August 11, 2024 1

As far as I can tell, this is just never going to work. See rust-lang/rust#25041 for more discussion, where it seems to me the issue has been interpreted as "confusing" rather than a bug to fix. Some reasons are given but I don't quite understand them. I don't see any movement to resolve it, so after half a decade, I'm giving up and calling this wontfix.

I would very much love to make quickcheck work with closures though. So if there are any fresh ideas, we can re-open is this issue.

from quickcheck.

abr-egn avatar abr-egn commented on August 11, 2024

That does work, thank you. I'm a bit baffled that it's required since it's trivially inferrable type information...

from quickcheck.

BurntSushi avatar BurntSushi commented on August 11, 2024

I'm pretty sure it's a known bug, but I can't find it in the Rust issue tracker at the moment. I think this happened when Rust moved everything over to unboxed closures. Unfortunately, I can't remember why this happens.

from quickcheck.

tomjakubowski avatar tomjakubowski commented on August 11, 2024

The PR that introduced this, I think, is rust-lang/rust#19891. I too remember seeing something that indicated this coercion is supposed to exist at some point but can't find it either.

from quickcheck.

milibopp avatar milibopp commented on August 11, 2024

Afaik, functions now implement the Fn(…) -> … traits. So I think it would actually be cleaner if quickcheck would impl<F: Fn(…) -> …> Testable for F instead of coercing to a trait object.

Edit: that does not work together with the coherence rules, does it?

from quickcheck.

BurntSushi avatar BurntSushi commented on August 11, 2024

I've tried really hard to work around this (by pursuing impls with Fn instead of fn) and I haven't been able to come up with a solution yet.

from quickcheck.

BurntSushi avatar BurntSushi commented on August 11, 2024

I think I'm currently blocked on this by this bug: rust-lang/rust#25041 (Well, I think it's a bug. It sure feels like it.)

from quickcheck.

michaelsproul avatar michaelsproul commented on August 11, 2024

cc me

from quickcheck.

FranklinChen avatar FranklinChen commented on August 11, 2024

Just to clarify: we are currently blocked on being able to quickcheck an arbitrary closure? (Important to be able to nest to stage generation of values, as in Haskell QuickCheck and Scala ScalaCheck.)

from quickcheck.

BurntSushi avatar BurntSushi commented on August 11, 2024

@FranklinChen Yup. I might be missing another solution to the problem, but the straight-forward path is to implement Testable on closure types, and the bug in rust-lang/rust#25041 seems to be preventing that.

from quickcheck.

shepmaster avatar shepmaster commented on August 11, 2024

While this still doesn't seem possible at the type level yet, you can reduce a bit of boilerplate by using _ when casting to the function pointer:

fn prop(xs: Vec<i32>) -> bool {
    xs == reverse(&reverse(&xs[..])[..])
}
quickcheck(prop as fn(_) -> _);

This is a bit nicer as you only have to duplicate the number of arguments, not the types.

from quickcheck.

FranklinChen avatar FranklinChen commented on August 11, 2024

@shepmaster Ah, thanks for that tip. Could a macro automate that?

from quickcheck.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.