New patches: [Add GenT module Felix Martini **20070811142815] { addfile ./Test/QuickCheck/GenT.hs hunk ./Test/QuickCheck/GenT.hs 1 +------------------------------------------------------------------------ +-- | +-- Module : Test.QuickCheck.GenT +-- Copyright : 2007 Felix Martini +-- License : BSD-style +-- +-- Maintainer : libraries@haskell.org +-- Stability : experimental +-- Portability : non-portable (multi-parameter type classes) +-- +-- GenT is the monad transformer variant of the 'Gen' monad. +-- +------------------------------------------------------------------------ + +module Test.QuickCheck.GenT where + +import Test.QuickCheck.Gen +import Control.Monad.Trans (MonadIO, MonadTrans, lift, liftIO) +import System.Random (StdGen, split) + +newtype GenT m a = GenT { unGenT :: StdGen -> Int -> m a } + +instance (Monad m) => Functor (GenT m) where + fmap f m = GenT $ \r n -> do + a <- unGenT m r n + return (f a) + +instance (Monad m) => Monad (GenT m) where + return a = GenT (\_ _ -> return a) + m >>= k = GenT $ \r n -> do + let (r1, r2) = split r + a <- unGenT m r1 n + unGenT (k a) r2 n + fail msg = GenT (\_ _ -> fail msg) + +instance MonadTrans GenT where + lift m = GenT (\_ _ -> m) + +instance (MonadIO m) => MonadIO (GenT m) where + liftIO = lift . liftIO + +-- | Convert a generator to a GenT m action. +fromGen :: (Monad m) => Gen a -> GenT m a +fromGen g = GenT $ \r n -> return (unGen g r n) + +-- | Convert a GenT m action to a generator of monadic values. +toGen :: GenT m a -> Gen (m a) +toGen gt = MkGen (\r n -> (unGenT gt r n)) + } [Add GenT to exposed modules list in cabal file Felix Martini **20070811142948] { hunk ./QuickCheck.cabal 17 + Test.QuickCheck.GenT, } Context: [Haddock tweak. bringert@cs.chalmers.se**20061126234053] [Added a version of sampling that returns the test cases dpt@math.columbia.edu**20061126220704] [Added LICENSE file. bringert@cs.chalmers.se**20061126232241] [Fixed silly missed use of Positive constructor. Reported by Audrey Tang. bringert@cs.chalmers.se**20061124212824] [Added README. bringert@cs.chalmers.se**20061123144917] [Some haddock mark-up fixes to support haddock 0.7. bringert@cs.chalmers.se**20061123144831] [Removed BUGS. bringert@cs.chalmers.se**20061123144204] [Changed distribution of NonNegative to 1:5 for 0:everything else (was 9:1). bringert@cs.chalmers.se**20061120210126] [Added NonZero and reimplemented Positive in terms of NonZero and NonNegative. bringert@cs.chalmers.se**20061120205417] [Added BUGS file. bringert@cs.chalmers.se**20061120205405] [Added Integral and Real instances for Positive and NonNegative. bringert@cs.chalmers.se**20061120204544] [Some haddock tweaks. bringert@cs.chalmers.se**20061120112922] [More haddock comments. bringert@cs.chalmers.se**20061120112532] [More haddock and export list fixes. bringert@cs.chalmers.se**20061117201830] [Added lots of Haddock comments and cleaned up export lists. bringert@cs.chalmers.se**20061117200346] [Commented out generics import that Haddock choked on. bringert@cs.chalmers.se**20061117152818] [Removed shrinkSub workarounds for old GHC bugs. bringert@cs.chalmers.se**20061117152630] [Get rid of the last uses of modules from the haskell98 package, replace with base modules. bringert@cs.chalmers.se**20061117152400] [Added Cabal build system. bringert@cs.chalmers.se**20061117152230] [Removed Koen's CVS update script. bringert@cs.chalmers.se**20061117151819] [Renamed modules to Test.QuickCheck.*. bringert@cs.chalmers.se**20061117151417] [More fixes to get examples to compile. bringert@cs.chalmers.se**20061114164526] [Fixed some imports in examples. bringert@cs.chalmers.se**20061114163012] [Fixed Chalmers/QuickCheck/Monadic.hs to compile with GHC 6.6. bringert@cs.chalmers.se**20061114162953] [Moved examples to a top-level directory. bringert@cs.chalmers.se**20061114160643] [Fixed ExSet2 and ExLambda to compile with GHC 6.6. bringert@cs.chalmers.se**20061114160531] [Comment out generics stuff to compile with GHC 6.6. bringert@cs.chalmers.se**20061114160414] [Renamed QuickCheck to Chalmers to get module names right. bringert@cs.chalmers.se**20061114160326] [Tailorization of QuickCheck tailor@momo.medic.chalmers.se**20061114165514 Import of the upstream sources from the repository /users/cs/koen/CvsRoot as of revision 2006-05-03 18:37:52 by koen ] Patch bundle hash: 55441249953b0020623e2d28197f3a452e5e1724