Hi i have the following code
import Data.Maybe
import Test.QuickCheck
import System.Random
rndExpr :: Gen Expr -> IO Expr
rndExpr gen = do
rnd <- newStdGen
return (generate 5 rnd gen)
But i get "not in scope "generate", why is this so?
Regards Darren
Edit i am importing Test.QuickCheck but it still complaints about the "generate" is not in scope.
Edit 2
How would you write this function so that it would work with quickcheck version 2? I simple tried to put "unGen" where generate was with no succsess, i also installed quickcheck v 2 (cabal install QuickCheck-2.1.0.3)
I need a function with following properties stdGen->Gen Expr->Expr'
and unGen seem to give me that functionality, but as I said, my compiler cant find that function. Are there any other functions that I could use for this problem?
It seems like you are using generators from Test.QuickCheck, and generate is a function from version 1 of quickCheck. In version 2 of quickCheck things are a bit different so there is no such function. However, you atleast need to import Test.QuickCheck, and similar functionality can be gotten from
unGen
like this:Please note that
unGen
is in Test.QuickCheck.Gen so you have to import that too.generate
isn't a function inSystem.Random
. Perhaps you are looking fornext
?EDIT: Let me be clear: I don't know why you are using QuickCheck/Arbitrary for a task that Random/MonadRandom would seem to be more fitting. I'll assume you considered your options and move on.
Must you select your generator? Can't you use
sample' :: Gen a -> IO a
?This should work for QC2.
OTOH, if you really want to use your own
StdGen
(or want to avoid IO) then try:This will use the
StdGen
namedg
and a count (0
here,) to generate your value. Because unGen doesn't step the generator, and the counter stepping doesn't give good randomness properties (it seems, you can try and see for yourself) you might end up wanting to wrap this with something that generatesStdGen
s (yuck).If you don't know what version package you are using then run:
In my setup (seen above) I have both 1 and 2, but 2 is hidden (the
()
means hidden) so when I use GHCi and importTest.QuickCheck
it's version 1 that I get.