Re: [Haskell-cafe] Generating random arguments for a function
In general you can't do this whether you use pats of QuickCheck or not - `randomEvalute` would need to inspect the supplied function to see how many input parameters it has so it can list them, but there is no such introspection in Haskell. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Generating random arguments for a function
* Stephen Tetley stephen.tet...@gmail.com [2013-01-13 08:49:08+] In general you can't do this whether you use pats of QuickCheck or not - `randomEvalute` would need to inspect the supplied function to see how many input parameters it has so it can list them, but there is no such introspection in Haskell. This can be done with relatively simple type class hackery. In fact, QuickCheck already does that in order to generate arguments and print them in case of failure. Roman ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Generating random arguments for a function
Yes - I was just checking the first QuickCheck paper to see how the authors did this. You would need a new type class that works like `Testable` and the versions of associated machinery `forAll` and `evaluate` to unroll function application. On 13 January 2013 09:28, Roman Cheplyaka r...@ro-che.info wrote: This can be done with relatively simple type class hackery. In fact, QuickCheck already does that in order to generate arguments and print them in case of failure. Roman ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Generating random arguments for a function
I have a working code of this but for that I have to reimplement Arbitrary and Testable typeclasses which I don't want to do. I thought it might be possible to use parts of quickcheck without actually changing its code but still I am unable to find a suitable solution. -Satvik On Sun, Jan 13, 2013 at 2:58 PM, Roman Cheplyaka r...@ro-che.info wrote: * Stephen Tetley stephen.tet...@gmail.com [2013-01-13 08:49:08+] In general you can't do this whether you use pats of QuickCheck or not - `randomEvalute` would need to inspect the supplied function to see how many input parameters it has so it can list them, but there is no such introspection in Haskell. This can be done with relatively simple type class hackery. In fact, QuickCheck already does that in order to generate arguments and print them in case of failure. Roman ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Generating random arguments for a function
I think it's more complicated because he doesn't know what the return type or arity of the function is. In QuickCheck they know the return type of a property is Bool. In this case, we only know that the return type is an instance of Show. I don't think that's enough to simply implement this. On Sunday, January 13, 2013, Stephen Tetley wrote: Yes - I was just checking the first QuickCheck paper to see how the authors did this. You would need a new type class that works like `Testable` and the versions of associated machinery `forAll` and `evaluate` to unroll function application. On 13 January 2013 09:28, Roman Cheplyaka r...@ro-che.info javascript:; wrote: This can be done with relatively simple type class hackery. In fact, QuickCheck already does that in order to generate arguments and print them in case of failure. Roman ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org javascript:; http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Generating random arguments for a function
Hi, Am Sonntag, den 13.01.2013, 07:34 -0800 schrieb Bob Ippolito: I think it's more complicated because he doesn't know what the return type or arity of the function is. In QuickCheck they know the return type of a property is Bool. In this case, we only know that the return type is an instance of Show. I don't think that's enough to simply implement this. I posted on SE an answer that tries to do it with OverlappingInstances: http://stackoverflow.com/questions/14294802/evaluating-function-at-random-arguments-using-quickcheck/14295179#14295179 Greetings, Joachim -- Joachim nomeata Breitner m...@joachim-breitner.de | nome...@debian.org | GPG: 0x4743206C xmpp: nome...@joachim-breitner.de | http://www.joachim-breitner.de/ signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Generating random arguments for a function
I am trying to use quickcheck to generate random arguments of a given function (assuming all its types have Arbitrary instance and Show instance) along with the evaluation of the function at those arguments. Suppose I have a function add :: Int - Int - Int add a b = a+b Then I assume a behavior like randomEvaluate add ([1,3],4) where 1 and 3 are random values generated for `Int` and 4 is `f 1 3`. I have asked this on SOhttp://stackoverflow.com/questions/14294802/evaluating-function-at-random-arguments-using-quickcheck but am not fully satisfied with the answers. -Satvik ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe