Hi all,
I know Haskell rather well and I always find its QuickCheck tool very pleasant so I decided to try to implement it in pure.
So here it is (there is a download link at the beginning of the post):
http://purelibs.blogspot.fr/2013/05/quickcheck-tutorial-000.htmlIts development is at a very early stage but I already like the way the arguments of a function can be manipulated out of the function, thanks to the get_fundef function.
As a matter of fact, this is that same function that make me wonder.
If I understand well, a function defined as
> f x y = somecomputation x y
implies that get_fundef f will output something useful whereas if
> g = \ x y -> process x y
then g is a closure and get_fundef can't evaluate it. Is it correct ?
My question is about manipulating the arguments of g the same way get_fundef permits the manipulation of the f arguments. Is it possible ? For a concrete application, I need to enable a quickcheck user to define properties the f way as well as the g way, then, whatever way is chosen, the quickcheck function parses the property (see get_types), chooses the right arguments (see arbitrary in the source), and applies the property to the arguments. At the moment, only the f way is coded:
get_types f = go ((\[a-->_]->a) $ get_fundef f) [] with
go g ts = if ~(applp g) then ts else go (next g) (get_type g : ts);
get_type = (\ (_ __type__ t) -> t) . (\ (_@_ x) -> x);
next = (\ (x@_ _) -> x);
end;
quickcheck prop = catch falsified (go 0) with
go 100 = puts "OK, passed 100 tests." $$ ();
go i = if apply prop args
then go (i+1)
else throw (args,i) when args = map arbitrary (get_types prop) end;
falsified (args,i) = puts ("Falsifiable, after " + str i + " tests:\n" + str args) $$ ();
apply f [] = f;
apply f (a:as) = apply (f a) as
end;
(please, see the post and the source for the context and all details).
By the way, any advice on the code or anything else is welcome!