{-# OPTIONS_HADDOCK not-home #-}
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DoAndIfThenElse #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
#if __GLASGOW_HASKELL__ >= 806
{-# LANGUAGE DerivingVia #-}
#endif
module Hedgehog.Internal.Gen (
Gen
, GenT(..)
, MonadGen(..)
, generalize
, shrink
, prune
, small
, scale
, resize
, sized
, integral
, integral_
, int
, int8
, int16
, int32
, int64
, word
, word8
, word16
, word32
, word64
, realFloat
, realFrac_
, float
, double
, enum
, enumBounded
, bool
, bool_
, binit
, octit
, digit
, hexit
, lower
, upper
, alpha
, alphaNum
, ascii
, latin1
, unicode
, unicodeAll
, string
, text
, utf8
, bytes
, constant
, element
, element_
, choice
, frequency
, recursive
, discard
, ensure
, filter
, mapMaybe
, filterT
, mapMaybeT
, just
, justT
, maybe
, either
, either_
, list
, seq
, nonEmpty
, set
, map
, freeze
, subterm
, subtermM
, subterm2
, subtermM2
, subterm3
, subtermM3
, subsequence
, shuffle
, shuffleSeq
, sample
, print
, printTree
, printWith
, printTreeWith
, renderTree
, runGenT
, evalGen
, evalGenT
, mapGenT
, generate
, toTree
, toTreeMaybeT
, fromTree
, fromTreeT
, fromTreeMaybeT
, runDiscardEffect
, runDiscardEffectT
, golden
, atLeast
, isSurrogate
, isNoncharacter
, Vec(..)
, Nat(..)
, subtermMVec
) where
import Control.Applicative (Alternative(..),liftA2)
import Control.Monad (MonadPlus(..), filterM, guard, replicateM, join)
import Control.Monad.Base (MonadBase(..))
import Control.Monad.Trans.Control (MonadBaseControl(..))
import Control.Monad.Catch (MonadThrow(..), MonadCatch(..))
import Control.Monad.Error.Class (MonadError(..))
import Control.Monad.IO.Class (MonadIO(..))
import Control.Monad.Morph (MFunctor(..), MMonad(..))
import qualified Control.Monad.Morph as Morph
import Control.Monad.Primitive (PrimMonad(..))
import Control.Monad.Reader.Class (MonadReader(..))
import Control.Monad.State.Class (MonadState(..))
import Control.Monad.Trans.Class (MonadTrans(..))
import Control.Monad.Trans.Except (ExceptT(..))
import Control.Monad.Trans.Identity (IdentityT(..))
import Control.Monad.Trans.Maybe (MaybeT(..))
import Control.Monad.Trans.Reader (ReaderT(..))
import Control.Monad.Trans.Resource (MonadResource(..))
import qualified Control.Monad.Trans.State.Lazy as Lazy
import qualified Control.Monad.Trans.State.Strict as Strict
import qualified Control.Monad.Trans.Writer.Lazy as Lazy
import qualified Control.Monad.Trans.Writer.Strict as Strict
import Control.Monad.Writer.Class (MonadWriter(..))
import Control.Monad.Zip (MonadZip(..))
import Data.Bifunctor (first)
import Data.ByteString (ByteString)
import qualified Data.ByteString as ByteString
import qualified Data.Char as Char
import Data.Foldable (for_, toList)
import Data.Functor.Identity (Identity(..))
import Data.Int (Int8, Int16, Int32, Int64)
import Data.Kind (Type)
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as NonEmpty
import Data.Map (Map)
import qualified Data.Map as Map
import qualified Data.Maybe as Maybe
import qualified Data.Semigroup as Semigroup
import Data.Sequence (Seq)
import qualified Data.Sequence as Seq
import Data.Set (Set)
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Data.Word (Word8, Word16, Word32, Word64)
import Hedgehog.Internal.Distributive (MonadTransDistributive(..))
import Hedgehog.Internal.Prelude hiding (either, maybe, seq)
import Hedgehog.Internal.Seed (Seed)
import qualified Hedgehog.Internal.Seed as Seed
import qualified Hedgehog.Internal.Shrink as Shrink
import Hedgehog.Internal.Tree (Tree, TreeT(..), NodeT(..))
import qualified Hedgehog.Internal.Tree as Tree
import Hedgehog.Range (Size, Range)
import qualified Hedgehog.Range as Range
#if __GLASGOW_HASKELL__ < 808
import qualified Control.Monad.Fail as Fail
#endif
#if __GLASGOW_HASKELL__ < 806
import Data.Coerce (coerce)
#endif
type Gen =
GenT Identity
newtype GenT m a =
GenT {
forall (m :: * -> *) a.
GenT m a -> Size -> Seed -> TreeT (MaybeT m) a
unGenT :: Size -> Seed -> TreeT (MaybeT m) a
}
runGenT :: Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT :: forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
seed (GenT Size -> Seed -> TreeT (MaybeT m) a
m) =
Size -> Seed -> TreeT (MaybeT m) a
m Size
size Seed
seed
evalGen :: Size -> Seed -> Gen a -> Maybe (Tree a)
evalGen :: forall a. Size -> Seed -> Gen a -> Maybe (Tree a)
evalGen Size
size Seed
seed =
forall a b. (a -> Maybe b) -> Tree a -> Maybe (Tree b)
Tree.mapMaybe forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (m :: * -> *) a.
Monad m =>
Size -> Seed -> GenT m a -> TreeT m (Maybe a)
evalGenT Size
size Seed
seed
evalGenT :: Monad m => Size -> Seed -> GenT m a -> TreeT m (Maybe a)
evalGenT :: forall (m :: * -> *) a.
Monad m =>
Size -> Seed -> GenT m a -> TreeT m (Maybe a)
evalGenT Size
size Seed
seed =
forall (m :: * -> *) a.
Monad m =>
TreeT (MaybeT m) a -> TreeT m (Maybe a)
runDiscardEffectT forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
seed
mapGenT :: (TreeT (MaybeT m) a -> TreeT (MaybeT n) b) -> GenT m a -> GenT n b
mapGenT :: forall (m :: * -> *) a (n :: * -> *) b.
(TreeT (MaybeT m) a -> TreeT (MaybeT n) b) -> GenT m a -> GenT n b
mapGenT TreeT (MaybeT m) a -> TreeT (MaybeT n) b
f GenT m a
gen =
forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
size Seed
seed ->
TreeT (MaybeT m) a -> TreeT (MaybeT n) b
f (forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
seed GenT m a
gen)
fromTree :: MonadGen m => Tree a -> m a
fromTree :: forall (m :: * -> *) a. MonadGen m => Tree a -> m a
fromTree =
forall (m :: * -> *) a. MonadGen m => TreeT (GenBase m) a -> m a
fromTreeT forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist (forall (m :: * -> *) a. Monad m => Identity a -> m a
Morph.generalize)
fromTreeT :: MonadGen m => TreeT (GenBase m) a -> m a
fromTreeT :: forall (m :: * -> *) a. MonadGen m => TreeT (GenBase m) a -> m a
fromTreeT TreeT (GenBase m) a
x =
forall (m :: * -> *) a.
MonadGen m =>
TreeT (MaybeT (GenBase m)) a -> m a
fromTreeMaybeT forall a b. (a -> b) -> a -> b
$
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist (forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> Maybe a
Just) TreeT (GenBase m) a
x
fromTreeMaybeT :: MonadGen m => TreeT (MaybeT (GenBase m)) a -> m a
fromTreeMaybeT :: forall (m :: * -> *) a.
MonadGen m =>
TreeT (MaybeT (GenBase m)) a -> m a
fromTreeMaybeT TreeT (MaybeT (GenBase m)) a
x =
forall (m :: * -> *) a. MonadGen m => GenT (GenBase m) a -> m a
fromGenT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
_ Seed
_ ->
TreeT (MaybeT (GenBase m)) a
x
toTree :: forall m a. (MonadGen m, GenBase m ~ Identity) => m a -> m (Tree a)
toTree :: forall (m :: * -> *) a.
(MonadGen m, GenBase m ~ Identity) =>
m a -> m (Tree a)
toTree =
forall (m :: * -> *) (n :: * -> *) a b.
(MonadGen m, MonadGen n) =>
(GenT (GenBase m) a -> GenT (GenBase n) b) -> m a -> n b
withGenT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a (n :: * -> *) b.
(TreeT (MaybeT m) a -> TreeT (MaybeT n) b) -> GenT m a -> GenT n b
mapGenT (forall b a. b -> (a -> b) -> Maybe a -> b
Maybe.maybe forall (f :: * -> *) a. Alternative f => f a
empty forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. TreeT (MaybeT Identity) a -> Maybe (Tree a)
runDiscardEffect)
toTreeMaybeT :: MonadGen m => m a -> m (TreeT (MaybeT (GenBase m)) a)
toTreeMaybeT :: forall (m :: * -> *) a.
MonadGen m =>
m a -> m (TreeT (MaybeT (GenBase m)) a)
toTreeMaybeT =
forall (m :: * -> *) (n :: * -> *) a b.
(MonadGen m, MonadGen n) =>
(GenT (GenBase m) a -> GenT (GenBase n) b) -> m a -> n b
withGenT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a (n :: * -> *) b.
(TreeT (MaybeT m) a -> TreeT (MaybeT n) b) -> GenT m a -> GenT n b
mapGenT forall (f :: * -> *) a. Applicative f => a -> f a
pure
runDiscardEffect :: TreeT (MaybeT Identity) a -> Maybe (Tree a)
runDiscardEffect :: forall a. TreeT (MaybeT Identity) a -> Maybe (Tree a)
runDiscardEffect =
forall a b. (a -> Maybe b) -> Tree a -> Maybe (Tree b)
Tree.mapMaybe forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (m :: * -> *) a.
Monad m =>
TreeT (MaybeT m) a -> TreeT m (Maybe a)
runDiscardEffectT
runDiscardEffectT :: Monad m => TreeT (MaybeT m) a -> TreeT m (Maybe a)
runDiscardEffectT :: forall (m :: * -> *) a.
Monad m =>
TreeT (MaybeT m) a -> TreeT m (Maybe a)
runDiscardEffectT =
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT
generalize :: Monad m => Gen a -> GenT m a
generalize :: forall (m :: * -> *) a. Monad m => Gen a -> GenT m a
generalize =
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. Monad m => Identity a -> m a
Morph.generalize
class (Monad m, Monad (GenBase m)) => MonadGen m where
type GenBase m :: (Type -> Type)
toGenT :: m a -> GenT (GenBase m) a
fromGenT :: GenT (GenBase m) a -> m a
withGenT :: (MonadGen m, MonadGen n) => (GenT (GenBase m) a -> GenT (GenBase n) b) -> m a -> n b
withGenT :: forall (m :: * -> *) (n :: * -> *) a b.
(MonadGen m, MonadGen n) =>
(GenT (GenBase m) a -> GenT (GenBase n) b) -> m a -> n b
withGenT GenT (GenBase m) a -> GenT (GenBase n) b
f =
forall (m :: * -> *) a. MonadGen m => GenT (GenBase m) a -> m a
fromGenT forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenT (GenBase m) a -> GenT (GenBase n) b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadGen m => m a -> GenT (GenBase m) a
toGenT
instance Monad m => MonadGen (GenT m) where
type GenBase (GenT m) =
m
toGenT :: forall a. GenT m a -> GenT (GenBase (GenT m)) a
toGenT =
forall a. a -> a
id
fromGenT :: forall a. GenT (GenBase (GenT m)) a -> GenT m a
fromGenT =
forall a. a -> a
id
instance MonadGen m => MonadGen (IdentityT m) where
type GenBase (IdentityT m) =
IdentityT (GenBase m)
toGenT :: forall a. IdentityT m a -> GenT (GenBase (IdentityT m)) a
toGenT =
forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => m a -> GenT (GenBase m) a
toGenT
fromGenT :: forall a. GenT (GenBase (IdentityT m)) a -> IdentityT m a
fromGenT =
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => GenT (GenBase m) a -> m a
fromGenT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT
instance MonadGen m => MonadGen (MaybeT m) where
type GenBase (MaybeT m) =
MaybeT (GenBase m)
toGenT :: forall a. MaybeT m a -> GenT (GenBase (MaybeT m)) a
toGenT =
forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => m a -> GenT (GenBase m) a
toGenT
fromGenT :: forall a. GenT (GenBase (MaybeT m)) a -> MaybeT m a
fromGenT =
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => GenT (GenBase m) a -> m a
fromGenT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT
instance MonadGen m => MonadGen (ExceptT x m) where
type GenBase (ExceptT x m) =
ExceptT x (GenBase m)
toGenT :: forall a. ExceptT x m a -> GenT (GenBase (ExceptT x m)) a
toGenT =
forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => m a -> GenT (GenBase m) a
toGenT
fromGenT :: forall a. GenT (GenBase (ExceptT x m)) a -> ExceptT x m a
fromGenT =
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => GenT (GenBase m) a -> m a
fromGenT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT
instance MonadGen m => MonadGen (ReaderT r m) where
type GenBase (ReaderT r m) =
ReaderT r (GenBase m)
toGenT :: forall a. ReaderT r m a -> GenT (GenBase (ReaderT r m)) a
toGenT =
forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => m a -> GenT (GenBase m) a
toGenT
fromGenT :: forall a. GenT (GenBase (ReaderT r m)) a -> ReaderT r m a
fromGenT =
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => GenT (GenBase m) a -> m a
fromGenT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT
instance MonadGen m => MonadGen (Lazy.StateT r m) where
type GenBase (Lazy.StateT r m) =
Lazy.StateT r (GenBase m)
toGenT :: forall a. StateT r m a -> GenT (GenBase (StateT r m)) a
toGenT =
forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => m a -> GenT (GenBase m) a
toGenT
fromGenT :: forall a. GenT (GenBase (StateT r m)) a -> StateT r m a
fromGenT =
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => GenT (GenBase m) a -> m a
fromGenT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT
instance MonadGen m => MonadGen (Strict.StateT r m) where
type GenBase (Strict.StateT r m) =
Strict.StateT r (GenBase m)
toGenT :: forall a. StateT r m a -> GenT (GenBase (StateT r m)) a
toGenT =
forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => m a -> GenT (GenBase m) a
toGenT
fromGenT :: forall a. GenT (GenBase (StateT r m)) a -> StateT r m a
fromGenT =
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => GenT (GenBase m) a -> m a
fromGenT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT
instance (MonadGen m, Monoid w) => MonadGen (Lazy.WriterT w m) where
type GenBase (Lazy.WriterT w m) =
Lazy.WriterT w (GenBase m)
toGenT :: forall a. WriterT w m a -> GenT (GenBase (WriterT w m)) a
toGenT =
forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => m a -> GenT (GenBase m) a
toGenT
fromGenT :: forall a. GenT (GenBase (WriterT w m)) a -> WriterT w m a
fromGenT =
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => GenT (GenBase m) a -> m a
fromGenT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT
instance (MonadGen m, Monoid w) => MonadGen (Strict.WriterT w m) where
type GenBase (Strict.WriterT w m) =
Strict.WriterT w (GenBase m)
toGenT :: forall a. WriterT w m a -> GenT (GenBase (WriterT w m)) a
toGenT =
forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => m a -> GenT (GenBase m) a
toGenT
fromGenT :: forall a. GenT (GenBase (WriterT w m)) a -> WriterT w m a
fromGenT =
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. MonadGen m => GenT (GenBase m) a -> m a
fromGenT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT
instance (Monad m, Semigroup a) => Semigroup (GenT m a) where
<> :: GenT m a -> GenT m a -> GenT m a
(<>) =
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Semigroup a => a -> a -> a
(Semigroup.<>)
instance (
Monad m, Monoid a
#if !MIN_VERSION_base(4,11,0)
, Semigroup a
#endif
) => Monoid (GenT m a) where
#if !MIN_VERSION_base(4,11,0)
mappend = (Semigroup.<>)
#endif
mempty :: GenT m a
mempty =
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
instance Functor m => Functor (GenT m) where
fmap :: forall a b. (a -> b) -> GenT m a -> GenT m b
fmap a -> b
f GenT m a
gen =
forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
seed Seed
size ->
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
seed Seed
size GenT m a
gen)
instance Monad m => Applicative (GenT m) where
pure :: forall a. a -> GenT m a
pure =
forall (m :: * -> *) a.
MonadGen m =>
TreeT (MaybeT (GenBase m)) a -> m a
fromTreeMaybeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure
<*> :: forall a b. GenT m (a -> b) -> GenT m a -> GenT m b
(<*>) GenT m (a -> b)
f GenT m a
m =
forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \ Size
size Seed
seed ->
case Seed -> (Seed, Seed)
Seed.split Seed
seed of
(Seed
sf, Seed
sm) ->
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a b. (a -> b) -> a -> b
($) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
sf GenT m (a -> b)
f forall (m :: * -> *) a b. MonadZip m => m a -> m b -> m (a, b)
`mzip`
forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
sm GenT m a
m
instance Monad m => Monad (GenT m) where
return :: forall a. a -> GenT m a
return =
forall (f :: * -> *) a. Applicative f => a -> f a
pure
>>= :: forall a b. GenT m a -> (a -> GenT m b) -> GenT m b
(>>=) GenT m a
m a -> GenT m b
k =
forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
size Seed
seed ->
case Seed -> (Seed, Seed)
Seed.split Seed
seed of
(Seed
sk, Seed
sm) ->
forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
sk forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> GenT m b
k forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
sm GenT m a
m
#if __GLASGOW_HASKELL__ < 808
fail =
Fail.fail
#endif
instance Monad m => MonadFail (GenT m) where
fail :: forall a. String -> GenT m a
fail =
forall a. HasCallStack => String -> a
error
instance Monad m => Alternative (GenT m) where
empty :: forall a. GenT m a
empty =
forall (m :: * -> *) a. MonadPlus m => m a
mzero
<|> :: forall a. GenT m a -> GenT m a -> GenT m a
(<|>) =
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
mplus
instance Monad m => MonadPlus (GenT m) where
mzero :: forall a. GenT m a
mzero =
forall (m :: * -> *) a.
MonadGen m =>
TreeT (MaybeT (GenBase m)) a -> m a
fromTreeMaybeT forall (m :: * -> *) a. MonadPlus m => m a
mzero
mplus :: forall a. GenT m a -> GenT m a -> GenT m a
mplus GenT m a
x GenT m a
y =
forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
size Seed
seed ->
case Seed -> (Seed, Seed)
Seed.split Seed
seed of
(Seed
sx, Seed
sy) ->
forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
sx GenT m a
x forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus`
forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
sy GenT m a
y
instance MonadTrans GenT where
lift :: forall (m :: * -> *) a. Monad m => m a -> GenT m a
lift =
forall (m :: * -> *) a.
MonadGen m =>
TreeT (MaybeT (GenBase m)) a -> m a
fromTreeMaybeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
instance MFunctor GenT where
hoist :: forall (m :: * -> *) (n :: * -> *) b.
Monad m =>
(forall a. m a -> n a) -> GenT m b -> GenT n b
hoist forall a. m a -> n a
f =
forall (m :: * -> *) a (n :: * -> *) b.
(TreeT (MaybeT m) a -> TreeT (MaybeT n) b) -> GenT m a -> GenT n b
mapGenT (forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist (forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall a. m a -> n a
f))
embedMaybeT ::
MonadTrans t
=> Monad n
=> Monad (t (MaybeT n))
=> (forall a. m a -> t (MaybeT n) a)
-> MaybeT m b
-> t (MaybeT n) b
embedMaybeT :: forall (t :: (* -> *) -> * -> *) (n :: * -> *) (m :: * -> *) b.
(MonadTrans t, Monad n, Monad (t (MaybeT n))) =>
(forall a. m a -> t (MaybeT n) a) -> MaybeT m b -> t (MaybeT n) b
embedMaybeT forall a. m a -> t (MaybeT n) a
f MaybeT m b
m =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall a. m a -> t (MaybeT n) a
f (forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT MaybeT m b
m)
embedTreeMaybeT ::
Monad n
=> (forall a. m a -> TreeT (MaybeT n) a)
-> TreeT (MaybeT m) b
-> TreeT (MaybeT n) b
embedTreeMaybeT :: forall (n :: * -> *) (m :: * -> *) b.
Monad n =>
(forall a. m a -> TreeT (MaybeT n) a)
-> TreeT (MaybeT m) b -> TreeT (MaybeT n) b
embedTreeMaybeT forall a. m a -> TreeT (MaybeT n) a
f TreeT (MaybeT m) b
tree_ =
forall (t :: (* -> *) -> * -> *) (n :: * -> *) (m :: * -> *) b.
(MMonad t, Monad n) =>
(forall a. m a -> t n a) -> t m b -> t n b
embed (forall (t :: (* -> *) -> * -> *) (n :: * -> *) (m :: * -> *) b.
(MonadTrans t, Monad n, Monad (t (MaybeT n))) =>
(forall a. m a -> t (MaybeT n) a) -> MaybeT m b -> t (MaybeT n) b
embedMaybeT forall a. m a -> TreeT (MaybeT n) a
f) TreeT (MaybeT m) b
tree_
embedGenT ::
Monad n
=> (forall a. m a -> GenT n a)
-> GenT m b
-> GenT n b
embedGenT :: forall (n :: * -> *) (m :: * -> *) b.
Monad n =>
(forall a. m a -> GenT n a) -> GenT m b -> GenT n b
embedGenT forall a. m a -> GenT n a
f GenT m b
gen =
forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
size Seed
seed ->
case Seed -> (Seed, Seed)
Seed.split Seed
seed of
(Seed
sf, Seed
sg) ->
(forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
sf forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. m a -> GenT n a
f) forall (n :: * -> *) (m :: * -> *) b.
Monad n =>
(forall a. m a -> TreeT (MaybeT n) a)
-> TreeT (MaybeT m) b -> TreeT (MaybeT n) b
`embedTreeMaybeT`
(forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
sg GenT m b
gen)
instance MMonad GenT where
embed :: forall (n :: * -> *) (m :: * -> *) b.
Monad n =>
(forall a. m a -> GenT n a) -> GenT m b -> GenT n b
embed =
forall (n :: * -> *) (m :: * -> *) b.
Monad n =>
(forall a. m a -> GenT n a) -> GenT m b -> GenT n b
embedGenT
distributeGenT :: Transformer t GenT m => GenT (t m) a -> t (GenT m) a
distributeGenT :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
Transformer t GenT m =>
GenT (t m) a -> t (GenT m) a
distributeGenT GenT (t m) a
x =
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
size Seed
seed ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a.
MonadGen m =>
TreeT (MaybeT (GenBase m)) a -> m a
fromTreeMaybeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (g :: (* -> *) -> * -> *) (f :: (* -> *) -> * -> *)
(m :: * -> *) a.
(MonadTransDistributive g, Transformer f g m) =>
g (f m) a -> f (g m) a
distributeT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
seed GenT (t m) a
x
instance MonadTransDistributive GenT where
type Transformer t GenT m = (
Monad (t (GenT m))
, Transformer t MaybeT m
, Transformer t TreeT (MaybeT m)
)
distributeT :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
Transformer t GenT m =>
GenT (t m) a -> t (GenT m) a
distributeT =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
Transformer t GenT m =>
GenT (t m) a -> t (GenT m) a
distributeGenT
instance PrimMonad m => PrimMonad (GenT m) where
type PrimState (GenT m) =
PrimState m
primitive :: forall a.
(State# (PrimState (GenT m))
-> (# State# (PrimState (GenT m)), a #))
-> GenT m a
primitive =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
instance MonadIO m => MonadIO (GenT m) where
liftIO :: forall a. IO a -> GenT m a
liftIO =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
instance MonadBase b m => MonadBase b (GenT m) where
liftBase :: forall α. b α -> GenT m α
liftBase =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase
#if __GLASGOW_HASKELL__ >= 806
deriving via (ReaderT Size (ReaderT Seed (TreeT (MaybeT m))))
instance MonadBaseControl b m => MonadBaseControl b (GenT m)
#else
instance MonadBaseControl b m => MonadBaseControl b (GenT m) where
type StM (GenT m) a = StM (GloopT m) a
liftBaseWith g = gloopToGen $ liftBaseWith $ \q -> g (\gen -> q (genToGloop gen))
restoreM = gloopToGen . restoreM
type GloopT m = ReaderT Size (ReaderT Seed (TreeT (MaybeT m)))
gloopToGen :: GloopT m a -> GenT m a
gloopToGen = coerce
genToGloop :: GenT m a -> GloopT m a
genToGloop = coerce
#endif
instance MonadThrow m => MonadThrow (GenT m) where
throwM :: forall e a. Exception e => e -> GenT m a
throwM =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM
instance MonadCatch m => MonadCatch (GenT m) where
catch :: forall e a. Exception e => GenT m a -> (e -> GenT m a) -> GenT m a
catch GenT m a
m e -> GenT m a
onErr =
forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
size Seed
seed ->
case Seed -> (Seed, Seed)
Seed.split Seed
seed of
(Seed
sm, Seed
se) ->
(forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
sm GenT m a
m) forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
`catch`
(forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
se forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> GenT m a
onErr)
instance MonadReader r m => MonadReader r (GenT m) where
ask :: GenT m r
ask =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall r (m :: * -> *). MonadReader r m => m r
ask
local :: forall a. (r -> r) -> GenT m a -> GenT m a
local r -> r
f GenT m a
m =
forall (m :: * -> *) a (n :: * -> *) b.
(TreeT (MaybeT m) a -> TreeT (MaybeT n) b) -> GenT m a -> GenT n b
mapGenT (forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local r -> r
f) GenT m a
m
instance MonadState s m => MonadState s (GenT m) where
get :: GenT m s
get =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall s (m :: * -> *). MonadState s m => m s
get
put :: s -> GenT m ()
put =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *). MonadState s m => s -> m ()
put
state :: forall a. (s -> (a, s)) -> GenT m a
state =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state
instance MonadWriter w m => MonadWriter w (GenT m) where
writer :: forall a. (a, w) -> GenT m a
writer =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall w (m :: * -> *) a. MonadWriter w m => (a, w) -> m a
writer
tell :: w -> GenT m ()
tell =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell
listen :: forall a. GenT m a -> GenT m (a, w)
listen GenT m a
m =
forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
size Seed
seed ->
forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
listen forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
seed GenT m a
m
pass :: forall a. GenT m (a, w -> w) -> GenT m a
pass GenT m (a, w -> w)
m =
forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
size Seed
seed ->
forall w (m :: * -> *) a. MonadWriter w m => m (a, w -> w) -> m a
pass forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
seed GenT m (a, w -> w)
m
instance MonadError e m => MonadError e (GenT m) where
throwError :: forall a. e -> GenT m a
throwError =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError
catchError :: forall a. GenT m a -> (e -> GenT m a) -> GenT m a
catchError GenT m a
m e -> GenT m a
onErr =
forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
size Seed
seed ->
case Seed -> (Seed, Seed)
Seed.split Seed
seed of
(Seed
sm, Seed
se) ->
(forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
sm GenT m a
m) forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError`
(forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
se forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> GenT m a
onErr)
instance MonadResource m => MonadResource (GenT m) where
liftResourceT :: forall a. ResourceT IO a -> GenT m a
liftResourceT =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadResource m => ResourceT IO a -> m a
liftResourceT
generate :: MonadGen m => (Size -> Seed -> a) -> m a
generate :: forall (m :: * -> *) a. MonadGen m => (Size -> Seed -> a) -> m a
generate Size -> Seed -> a
f =
forall (m :: * -> *) a. MonadGen m => GenT (GenBase m) a -> m a
fromGenT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
size Seed
seed ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Size -> Seed -> a
f Size
size Seed
seed)
shrink :: MonadGen m => (a -> [a]) -> m a -> m a
shrink :: forall (m :: * -> *) a. MonadGen m => (a -> [a]) -> m a -> m a
shrink a -> [a]
f =
forall (m :: * -> *) (n :: * -> *) a b.
(MonadGen m, MonadGen n) =>
(GenT (GenBase m) a -> GenT (GenBase n) b) -> m a -> n b
withGenT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a (n :: * -> *) b.
(TreeT (MaybeT m) a -> TreeT (MaybeT n) b) -> GenT m a -> GenT n b
mapGenT (forall (m :: * -> *) a.
Monad m =>
(a -> [a]) -> TreeT m a -> TreeT m a
Tree.expand a -> [a]
f)
prune :: MonadGen m => m a -> m a
prune :: forall (m :: * -> *) a. MonadGen m => m a -> m a
prune =
forall (m :: * -> *) (n :: * -> *) a b.
(MonadGen m, MonadGen n) =>
(GenT (GenBase m) a -> GenT (GenBase n) b) -> m a -> n b
withGenT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a (n :: * -> *) b.
(TreeT (MaybeT m) a -> TreeT (MaybeT n) b) -> GenT m a -> GenT n b
mapGenT (forall (m :: * -> *) a. Monad m => Int -> TreeT m a -> TreeT m a
Tree.prune Int
0)
sized :: MonadGen m => (Size -> m a) -> m a
sized :: forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
sized Size -> m a
f = do
Size -> m a
f forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *) a. MonadGen m => (Size -> Seed -> a) -> m a
generate (\Size
size Seed
_ -> Size
size)
resize :: MonadGen m => Size -> m a -> m a
resize :: forall (m :: * -> *) a. MonadGen m => Size -> m a -> m a
resize Size
size m a
gen =
forall (m :: * -> *) a. MonadGen m => (Size -> Size) -> m a -> m a
scale (forall a b. a -> b -> a
const Size
size) m a
gen
scale :: MonadGen m => (Size -> Size) -> m a -> m a
scale :: forall (m :: * -> *) a. MonadGen m => (Size -> Size) -> m a -> m a
scale Size -> Size
f =
forall (m :: * -> *) (n :: * -> *) a b.
(MonadGen m, MonadGen n) =>
(GenT (GenBase m) a -> GenT (GenBase n) b) -> m a -> n b
withGenT forall a b. (a -> b) -> a -> b
$ \GenT (GenBase m) a
gen ->
forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
size0 Seed
seed ->
let
size :: Size
size =
Size -> Size
f Size
size0
in
if Size
size forall a. Ord a => a -> a -> Bool
< Size
0 then
forall a. HasCallStack => String -> a
error String
"Hedgehog.Gen.scale: negative size"
else
forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
seed GenT (GenBase m) a
gen
small :: MonadGen m => m a -> m a
small :: forall (m :: * -> *) a. MonadGen m => m a -> m a
small =
forall (m :: * -> *) a. MonadGen m => (Size -> Size) -> m a -> m a
scale Size -> Size
golden
golden :: Size -> Size
golden :: Size -> Size
golden Size
x =
forall a b. (RealFrac a, Integral b) => a -> b
round (forall a b. (Integral a, Num b) => a -> b
fromIntegral Size
x forall a. Num a => a -> a -> a
* Double
0.61803398875 :: Double)
integral :: forall m a. (MonadGen m, Integral a) => Range a -> m a
integral :: forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral Range a
range =
let
origin_ :: a
origin_ =
forall a. Range a -> a
Range.origin Range a
range
binarySearchTree :: a -> a -> TreeT Identity a
binarySearchTree a
bottom a
top =
forall a. NodeT Identity a -> Tree a
Tree.Tree forall a b. (a -> b) -> a -> b
$
let
shrinks :: [a]
shrinks =
forall a. Integral a => a -> a -> [a]
Shrink.towards a
bottom a
top
children :: [TreeT Identity a]
children =
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith a -> a -> TreeT Identity a
binarySearchTree [a]
shrinks (forall a. Int -> [a] -> [a]
drop Int
1 [a]
shrinks)
in
forall (m :: * -> *) a. a -> [TreeT m a] -> NodeT m a
Tree.NodeT a
top [TreeT Identity a]
children
createTree :: a -> TreeT (MaybeT (GenBase m)) a
createTree a
root =
if a
root forall a. Eq a => a -> a -> Bool
== a
origin_ then
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
root
else
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall (m :: * -> *) a. Monad m => Identity a -> m a
Morph.generalize forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a. Monad m => a -> TreeT m a -> TreeT m a
Tree.consChild a
origin_ forall a b. (a -> b) -> a -> b
$
forall {a}. Integral a => a -> a -> TreeT Identity a
binarySearchTree a
origin_ a
root
in
forall (m :: * -> *) a. MonadGen m => GenT (GenBase m) a -> m a
fromGenT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
size Seed
seed ->
a -> TreeT (MaybeT (GenBase m)) a
createTree forall a b. (a -> b) -> a -> b
$ forall a c. (Integral a, Num c) => Range a -> Size -> Seed -> c
integralHelper Range a
range Size
size Seed
seed
integral_ :: (MonadGen m, Integral a) => Range a -> m a
integral_ :: forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral_ =
forall (m :: * -> *) a. MonadGen m => (Size -> Seed -> a) -> m a
generate forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a c. (Integral a, Num c) => Range a -> Size -> Seed -> c
integralHelper
integralHelper :: (Integral a, Num c) => Range a -> Size -> Seed -> c
integralHelper :: forall a c. (Integral a, Num c) => Range a -> Size -> Seed -> c
integralHelper Range a
range Size
size Seed
seed =
let
(a
x, a
y) =
forall a. Size -> Range a -> (a, a)
Range.bounds Size
size Range a
range
in
forall a. Num a => Integer -> a
fromInteger forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$
Integer -> Integer -> Seed -> (Integer, Seed)
Seed.nextInteger (forall a. Integral a => a -> Integer
toInteger a
x) (forall a. Integral a => a -> Integer
toInteger a
y) Seed
seed
int :: MonadGen m => Range Int -> m Int
int :: forall (m :: * -> *). MonadGen m => Range Int -> m Int
int =
forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral
int8 :: MonadGen m => Range Int8 -> m Int8
int8 :: forall (m :: * -> *). MonadGen m => Range Int8 -> m Int8
int8 =
forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral
int16 :: MonadGen m => Range Int16 -> m Int16
int16 :: forall (m :: * -> *). MonadGen m => Range Int16 -> m Int16
int16 =
forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral
int32 :: MonadGen m => Range Int32 -> m Int32
int32 :: forall (m :: * -> *). MonadGen m => Range Int32 -> m Int32
int32 =
forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral
int64 :: MonadGen m => Range Int64 -> m Int64
int64 :: forall (m :: * -> *). MonadGen m => Range Int64 -> m Int64
int64 =
forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral
word :: MonadGen m => Range Word -> m Word
word :: forall (m :: * -> *). MonadGen m => Range Word -> m Word
word =
forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral
word8 :: MonadGen m => Range Word8 -> m Word8
word8 :: forall (m :: * -> *). MonadGen m => Range Word8 -> m Word8
word8 =
forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral
word16 :: MonadGen m => Range Word16 -> m Word16
word16 :: forall (m :: * -> *). MonadGen m => Range Word16 -> m Word16
word16 =
forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral
word32 :: MonadGen m => Range Word32 -> m Word32
word32 :: forall (m :: * -> *). MonadGen m => Range Word32 -> m Word32
word32 =
forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral
word64 :: MonadGen m => Range Word64 -> m Word64
word64 :: forall (m :: * -> *). MonadGen m => Range Word64 -> m Word64
word64 =
forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral
realFloat :: (MonadGen m, RealFloat a) => Range a -> m a
realFloat :: forall (m :: * -> *) a. (MonadGen m, RealFloat a) => Range a -> m a
realFloat Range a
range =
forall (m :: * -> *) a. MonadGen m => (a -> [a]) -> m a -> m a
shrink (forall a. RealFloat a => a -> a -> [a]
Shrink.towardsFloat forall a b. (a -> b) -> a -> b
$ forall a. Range a -> a
Range.origin Range a
range) (forall (m :: * -> *) a. (MonadGen m, RealFrac a) => Range a -> m a
realFrac_ Range a
range)
realFrac_ :: (MonadGen m, RealFrac a) => Range a -> m a
realFrac_ :: forall (m :: * -> *) a. (MonadGen m, RealFrac a) => Range a -> m a
realFrac_ Range a
range =
forall (m :: * -> *) a. MonadGen m => (Size -> Seed -> a) -> m a
generate forall a b. (a -> b) -> a -> b
$ \Size
size Seed
seed ->
let
(a
x, a
y) =
forall a. Size -> Range a -> (a, a)
Range.bounds Size
size Range a
range
in
forall a b. (Real a, Fractional b) => a -> b
realToFrac forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$
Double -> Double -> Seed -> (Double, Seed)
Seed.nextDouble (forall a b. (Real a, Fractional b) => a -> b
realToFrac a
x) (forall a b. (Real a, Fractional b) => a -> b
realToFrac a
y) Seed
seed
float :: MonadGen m => Range Float -> m Float
float :: forall (m :: * -> *). MonadGen m => Range Float -> m Float
float =
forall (m :: * -> *) a. (MonadGen m, RealFloat a) => Range a -> m a
realFloat
double :: MonadGen m => Range Double -> m Double
double :: forall (m :: * -> *). MonadGen m => Range Double -> m Double
double =
forall (m :: * -> *) a. (MonadGen m, RealFloat a) => Range a -> m a
realFloat
enum :: (MonadGen m, Enum a) => a -> a -> m a
enum :: forall (m :: * -> *) a. (MonadGen m, Enum a) => a -> a -> m a
enum a
lo a
hi =
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Enum a => Int -> a
toEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral forall a b. (a -> b) -> a -> b
$
forall a. a -> a -> Range a
Range.constant (forall a. Enum a => a -> Int
fromEnum a
lo) (forall a. Enum a => a -> Int
fromEnum a
hi)
enumBounded :: (MonadGen m, Enum a, Bounded a) => m a
enumBounded :: forall (m :: * -> *) a. (MonadGen m, Enum a, Bounded a) => m a
enumBounded =
forall (m :: * -> *) a. (MonadGen m, Enum a) => a -> a -> m a
enum forall a. Bounded a => a
minBound forall a. Bounded a => a
maxBound
bool :: MonadGen m => m Bool
bool :: forall (m :: * -> *). MonadGen m => m Bool
bool =
forall (m :: * -> *) a. (MonadGen m, Enum a, Bounded a) => m a
enumBounded
bool_ :: MonadGen m => m Bool
bool_ :: forall (m :: * -> *). MonadGen m => m Bool
bool_ =
forall (m :: * -> *) a. MonadGen m => (Size -> Seed -> a) -> m a
generate forall a b. (a -> b) -> a -> b
$ \Size
_ Seed
seed ->
(forall a. Eq a => a -> a -> Bool
/= Integer
0) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> Seed -> (Integer, Seed)
Seed.nextInteger Integer
0 Integer
1 Seed
seed
binit :: MonadGen m => m Char
binit :: forall (m :: * -> *). MonadGen m => m Char
binit =
forall (m :: * -> *) a. (MonadGen m, Enum a) => a -> a -> m a
enum Char
'0' Char
'1'
octit :: MonadGen m => m Char
octit :: forall (m :: * -> *). MonadGen m => m Char
octit =
forall (m :: * -> *) a. (MonadGen m, Enum a) => a -> a -> m a
enum Char
'0' Char
'7'
digit :: MonadGen m => m Char
digit :: forall (m :: * -> *). MonadGen m => m Char
digit =
forall (m :: * -> *) a. (MonadGen m, Enum a) => a -> a -> m a
enum Char
'0' Char
'9'
hexit :: MonadGen m => m Char
hexit :: forall (m :: * -> *). MonadGen m => m Char
hexit =
forall (m :: * -> *) a. MonadGen m => [a] -> m a
element String
"0123456789aAbBcCdDeEfF"
lower :: MonadGen m => m Char
lower :: forall (m :: * -> *). MonadGen m => m Char
lower =
forall (m :: * -> *) a. (MonadGen m, Enum a) => a -> a -> m a
enum Char
'a' Char
'z'
upper :: MonadGen m => m Char
upper :: forall (m :: * -> *). MonadGen m => m Char
upper =
forall (m :: * -> *) a. (MonadGen m, Enum a) => a -> a -> m a
enum Char
'A' Char
'Z'
alpha :: MonadGen m => m Char
alpha :: forall (m :: * -> *). MonadGen m => m Char
alpha =
forall (m :: * -> *) a. MonadGen m => [a] -> m a
element String
"abcdefghiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
alphaNum :: MonadGen m => m Char
alphaNum :: forall (m :: * -> *). MonadGen m => m Char
alphaNum =
forall (m :: * -> *) a. MonadGen m => [a] -> m a
element String
"abcdefghiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
ascii :: MonadGen m => m Char
ascii :: forall (m :: * -> *). MonadGen m => m Char
ascii =
forall (m :: * -> *) a. (MonadGen m, Enum a) => a -> a -> m a
enum Char
'\0' Char
'\127'
latin1 :: MonadGen m => m Char
latin1 :: forall (m :: * -> *). MonadGen m => m Char
latin1 =
forall (m :: * -> *) a. (MonadGen m, Enum a) => a -> a -> m a
enum Char
'\0' Char
'\255'
unicode :: (MonadGen m) => m Char
unicode :: forall (m :: * -> *). MonadGen m => m Char
unicode =
let
s1 :: (Int, m Char)
s1 =
(Int
55296, forall (m :: * -> *) a. (MonadGen m, Enum a) => a -> a -> m a
enum Char
'\0' Char
'\55295')
s2 :: (Int, m Char)
s2 =
(Int
8190, forall (m :: * -> *) a. (MonadGen m, Enum a) => a -> a -> m a
enum Char
'\57344' Char
'\65533')
s3 :: (Int, m Char)
s3 =
(Int
1048576, forall (m :: * -> *) a. (MonadGen m, Enum a) => a -> a -> m a
enum Char
'\65536' Char
'\1114111')
in
forall (m :: * -> *) a. MonadGen m => [(Int, m a)] -> m a
frequency [(Int, m Char)
s1, (Int, m Char)
s2, (Int, m Char)
s3]
unicodeAll :: MonadGen m => m Char
unicodeAll :: forall (m :: * -> *). MonadGen m => m Char
unicodeAll =
forall (m :: * -> *) a. (MonadGen m, Enum a, Bounded a) => m a
enumBounded
isSurrogate :: Char -> Bool
isSurrogate :: Char -> Bool
isSurrogate Char
x =
Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\55296' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\57343'
isNoncharacter :: Char -> Bool
isNoncharacter :: Char -> Bool
isNoncharacter Char
x =
Char
x forall a. Eq a => a -> a -> Bool
== Char
'\65534' Bool -> Bool -> Bool
|| Char
x forall a. Eq a => a -> a -> Bool
== Char
'\65535'
string :: MonadGen m => Range Int -> m Char -> m String
string :: forall (m :: * -> *). MonadGen m => Range Int -> m Char -> m String
string =
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
list
text :: MonadGen m => Range Int -> m Char -> m Text
text :: forall (m :: * -> *). MonadGen m => Range Int -> m Char -> m Text
text Range Int
range =
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Text
Text.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). MonadGen m => Range Int -> m Char -> m String
string Range Int
range
utf8 :: MonadGen m => Range Int -> m Char -> m ByteString
utf8 :: forall (m :: * -> *).
MonadGen m =>
Range Int -> m Char -> m ByteString
utf8 Range Int
range =
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> ByteString
Text.encodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). MonadGen m => Range Int -> m Char -> m Text
text Range Int
range
bytes :: MonadGen m => Range Int -> m ByteString
bytes :: forall (m :: * -> *). MonadGen m => Range Int -> m ByteString
bytes Range Int
range =
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Word8] -> ByteString
ByteString.pack forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a. MonadGen m => [m a] -> m a
choice [
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
list Range Int
range forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). MonadGen m => Range Word8 -> m Word8
word8 forall a b. (a -> b) -> a -> b
$
forall a. a -> a -> Range a
Range.constant
(forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ Char -> Int
Char.ord Char
'a')
(forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ Char -> Int
Char.ord Char
'z')
, forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
list Range Int
range forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). MonadGen m => Range Word8 -> m Word8
word8 forall a b. (a -> b) -> a -> b
$
forall a. a -> a -> Range a
Range.constant forall a. Bounded a => a
minBound forall a. Bounded a => a
maxBound
]
constant :: MonadGen m => a -> m a
constant :: forall (m :: * -> *) a. MonadGen m => a -> m a
constant =
forall (f :: * -> *) a. Applicative f => a -> f a
pure
element :: MonadGen m => [a] -> m a
element :: forall (m :: * -> *) a. MonadGen m => [a] -> m a
element = \case
[] ->
forall a. HasCallStack => String -> a
error String
"Hedgehog.Gen.element: used with empty list"
[a]
xs -> do
Int
n <- forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral forall a b. (a -> b) -> a -> b
$ forall a. a -> a -> Range a
Range.constant Int
0 (forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs forall a. Num a => a -> a -> a
- Int
1)
pure $ [a]
xs forall a. [a] -> Int -> a
!! Int
n
element_ :: MonadGen m => [a] -> m a
element_ :: forall (m :: * -> *) a. MonadGen m => [a] -> m a
element_ = \case
[] ->
forall a. HasCallStack => String -> a
error String
"Hedgehog.Gen.element: used with empty list"
[a]
xs -> do
Int
n <- forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral_ forall a b. (a -> b) -> a -> b
$ forall a. a -> a -> Range a
Range.constant Int
0 (forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs forall a. Num a => a -> a -> a
- Int
1)
pure $ [a]
xs forall a. [a] -> Int -> a
!! Int
n
choice :: MonadGen m => [m a] -> m a
choice :: forall (m :: * -> *) a. MonadGen m => [m a] -> m a
choice = \case
[] ->
forall a. HasCallStack => String -> a
error String
"Hedgehog.Gen.choice: used with empty list"
[m a]
xs -> do
Int
n <- forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral forall a b. (a -> b) -> a -> b
$ forall a. a -> a -> Range a
Range.constant Int
0 (forall (t :: * -> *) a. Foldable t => t a -> Int
length [m a]
xs forall a. Num a => a -> a -> a
- Int
1)
[m a]
xs forall a. [a] -> Int -> a
!! Int
n
frequency :: MonadGen m => [(Int, m a)] -> m a
frequency :: forall (m :: * -> *) a. MonadGen m => [(Int, m a)] -> m a
frequency = \case
[] ->
forall a. HasCallStack => String -> a
error String
"Hedgehog.Gen.frequency: used with empty list"
[(Int, m a)]
xs0 -> do
let
pick :: t -> [(t, a)] -> a
pick t
n = \case
[] ->
forall a. HasCallStack => String -> a
error String
"Hedgehog.Gen.frequency/pick: used with empty list"
(t
k, a
x) : [(t, a)]
xs ->
if t
n forall a. Ord a => a -> a -> Bool
<= t
k then
a
x
else
t -> [(t, a)] -> a
pick (t
n forall a. Num a => a -> a -> a
- t
k) [(t, a)]
xs
iis :: [Int]
iis =
forall a. (a -> a -> a) -> [a] -> [a]
scanl1 forall a. Num a => a -> a -> a
(+) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> a
fst [(Int, m a)]
xs0)
total :: Int
total =
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> a
fst [(Int, m a)]
xs0)
Int
n <- forall (m :: * -> *) a. MonadGen m => (a -> [a]) -> m a -> m a
shrink (\Int
n -> forall a. (a -> Bool) -> [a] -> [a]
takeWhile (forall a. Ord a => a -> a -> Bool
< Int
n) [Int]
iis) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral_ forall a b. (a -> b) -> a -> b
$ forall a. a -> a -> Range a
Range.constant Int
1 Int
total
forall {t} {a}. (Ord t, Num t) => t -> [(t, a)] -> a
pick Int
n [(Int, m a)]
xs0
recursive :: MonadGen m => ([m a] -> m a) -> [m a] -> [m a] -> m a
recursive :: forall (m :: * -> *) a.
MonadGen m =>
([m a] -> m a) -> [m a] -> [m a] -> m a
recursive [m a] -> m a
f [m a]
nonrec [m a]
rec =
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
sized forall a b. (a -> b) -> a -> b
$ \Size
n ->
if Size
n forall a. Ord a => a -> a -> Bool
<= Size
1 then
[m a] -> m a
f [m a]
nonrec
else
[m a] -> m a
f forall a b. (a -> b) -> a -> b
$ [m a]
nonrec forall a. [a] -> [a] -> [a]
++ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (m :: * -> *) a. MonadGen m => m a -> m a
small [m a]
rec
discard :: MonadGen m => m a
discard :: forall (m :: * -> *) a. MonadGen m => m a
discard =
forall (m :: * -> *) a. MonadGen m => GenT (GenBase m) a -> m a
fromGenT forall (f :: * -> *) a. Alternative f => f a
empty
ensure :: MonadGen m => (a -> Bool) -> m a -> m a
ensure :: forall (m :: * -> *) a. MonadGen m => (a -> Bool) -> m a -> m a
ensure a -> Bool
p m a
gen = do
a
x <- m a
gen
if a -> Bool
p a
x then
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x
else
forall (m :: * -> *) a. MonadGen m => m a
discard
fromPred :: (a -> Bool) -> a -> Maybe a
fromPred :: forall a. (a -> Bool) -> a -> Maybe a
fromPred a -> Bool
p a
a = a
a forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (f :: * -> *). Alternative f => Bool -> f ()
guard (a -> Bool
p a
a)
filter :: (MonadGen m, GenBase m ~ Identity) => (a -> Bool) -> m a -> m a
filter :: forall (m :: * -> *) a.
(MonadGen m, GenBase m ~ Identity) =>
(a -> Bool) -> m a -> m a
filter a -> Bool
p =
forall (m :: * -> *) a b.
(MonadGen m, GenBase m ~ Identity) =>
(a -> Maybe b) -> m a -> m b
mapMaybe (forall a. (a -> Bool) -> a -> Maybe a
fromPred a -> Bool
p)
mapMaybe :: (MonadGen m, GenBase m ~ Identity) => (a -> Maybe b) -> m a -> m b
mapMaybe :: forall (m :: * -> *) a b.
(MonadGen m, GenBase m ~ Identity) =>
(a -> Maybe b) -> m a -> m b
mapMaybe a -> Maybe b
p m a
gen0 =
let
try :: Size -> m b
try Size
k =
if Size
k forall a. Ord a => a -> a -> Bool
> Size
100 then
forall (m :: * -> *) a. MonadGen m => m a
discard
else do
(a
x, m a
gen) <- forall (m :: * -> *) a. MonadGen m => m a -> m (a, m a)
freeze forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadGen m => (Size -> Size) -> m a -> m a
scale (Size
2 forall a. Num a => a -> a -> a
* Size
k forall a. Num a => a -> a -> a
+) m a
gen0
case a -> Maybe b
p a
x of
Just b
_ ->
forall (m :: * -> *) (n :: * -> *) a b.
(MonadGen m, MonadGen n) =>
(GenT (GenBase m) a -> GenT (GenBase n) b) -> m a -> n b
withGenT (forall (m :: * -> *) a (n :: * -> *) b.
(TreeT (MaybeT m) a -> TreeT (MaybeT n) b) -> GenT m a -> GenT n b
mapGenT (forall a b.
(a -> Maybe b)
-> TreeT (MaybeT Identity) a -> TreeT (MaybeT Identity) b
Tree.mapMaybeMaybeT a -> Maybe b
p)) m a
gen
Maybe b
Nothing ->
Size -> m b
try (Size
k forall a. Num a => a -> a -> a
+ Size
1)
in
Size -> m b
try Size
0
filterT :: MonadGen m => (a -> Bool) -> m a -> m a
filterT :: forall (m :: * -> *) a. MonadGen m => (a -> Bool) -> m a -> m a
filterT a -> Bool
p =
forall (m :: * -> *) a b.
MonadGen m =>
(a -> Maybe b) -> m a -> m b
mapMaybeT (forall a. (a -> Bool) -> a -> Maybe a
fromPred a -> Bool
p)
mapMaybeT :: MonadGen m => (a -> Maybe b) -> m a -> m b
mapMaybeT :: forall (m :: * -> *) a b.
MonadGen m =>
(a -> Maybe b) -> m a -> m b
mapMaybeT a -> Maybe b
p m a
gen0 =
let
try :: Size -> m b
try Size
k =
if Size
k forall a. Ord a => a -> a -> Bool
> Size
100 then
forall (m :: * -> *) a. MonadGen m => m a
discard
else do
(a
x, m a
gen) <- forall (m :: * -> *) a. MonadGen m => m a -> m (a, m a)
freeze forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadGen m => (Size -> Size) -> m a -> m a
scale (Size
2 forall a. Num a => a -> a -> a
* Size
k forall a. Num a => a -> a -> a
+) m a
gen0
case a -> Maybe b
p a
x of
Just b
_ ->
forall (m :: * -> *) (n :: * -> *) a b.
(MonadGen m, MonadGen n) =>
(GenT (GenBase m) a -> GenT (GenBase n) b) -> m a -> n b
withGenT (forall (m :: * -> *) a (n :: * -> *) b.
(TreeT (MaybeT m) a -> TreeT (MaybeT n) b) -> GenT m a -> GenT n b
mapGenT (forall (m :: * -> *) a b.
(Monad m, Alternative m) =>
(a -> Maybe b) -> TreeT m a -> TreeT m b
Tree.mapMaybeT a -> Maybe b
p)) m a
gen
Maybe b
Nothing ->
Size -> m b
try (Size
k forall a. Num a => a -> a -> a
+ Size
1)
in
Size -> m b
try Size
0
just :: (MonadGen m, GenBase m ~ Identity) => m (Maybe a) -> m a
just :: forall (m :: * -> *) a.
(MonadGen m, GenBase m ~ Identity) =>
m (Maybe a) -> m a
just m (Maybe a)
g = do
Maybe a
mx <- forall (m :: * -> *) a.
(MonadGen m, GenBase m ~ Identity) =>
(a -> Bool) -> m a -> m a
filter forall a. Maybe a -> Bool
Maybe.isJust m (Maybe a)
g
case Maybe a
mx of
Just a
x ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x
Maybe a
Nothing ->
forall a. HasCallStack => String -> a
error String
"Hedgehog.Gen.just: internal error, unexpected Nothing"
justT :: MonadGen m => m (Maybe a) -> m a
justT :: forall (m :: * -> *) a. MonadGen m => m (Maybe a) -> m a
justT m (Maybe a)
g = do
Maybe a
mx <- forall (m :: * -> *) a. MonadGen m => (a -> Bool) -> m a -> m a
filterT forall a. Maybe a -> Bool
Maybe.isJust m (Maybe a)
g
case Maybe a
mx of
Just a
x ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x
Maybe a
Nothing ->
forall a. HasCallStack => String -> a
error String
"Hedgehog.Gen.just: internal error, unexpected Nothing"
maybe :: MonadGen m => m a -> m (Maybe a)
maybe :: forall (m :: * -> *) a. MonadGen m => m a -> m (Maybe a)
maybe m a
gen =
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
sized forall a b. (a -> b) -> a -> b
$ \Size
n ->
forall (m :: * -> *) a. MonadGen m => [(Int, m a)] -> m a
frequency [
(Int
2, forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Maybe a
Nothing)
, (Int
1 forall a. Num a => a -> a -> a
+ forall a b. (Integral a, Num b) => a -> b
fromIntegral Size
n, forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
gen)
]
either :: MonadGen m => m a -> m b -> m (Either a b)
either :: forall (m :: * -> *) a b.
MonadGen m =>
m a -> m b -> m (Either a b)
either m a
genA m b
genB =
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
sized forall a b. (a -> b) -> a -> b
$ \Size
n ->
forall (m :: * -> *) a. MonadGen m => [(Int, m a)] -> m a
frequency [
(Int
2, forall a b. a -> Either a b
Left forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
genA)
, (Int
1 forall a. Num a => a -> a -> a
+ forall a b. (Integral a, Num b) => a -> b
fromIntegral Size
n, forall a b. b -> Either a b
Right forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m b
genB)
]
either_ :: MonadGen m => m a -> m b -> m (Either a b)
either_ :: forall (m :: * -> *) a b.
MonadGen m =>
m a -> m b -> m (Either a b)
either_ m a
genA m b
genB =
forall (m :: * -> *) a. MonadGen m => [m a] -> m a
choice [
forall a b. a -> Either a b
Left forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
genA
, forall a b. b -> Either a b
Right forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m b
genB
]
list :: MonadGen m => Range Int -> m a -> m [a]
list :: forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
list Range Int
range m a
gen =
let
interleave :: MaybeT (GenBase m) (NodeT m [TreeT (MaybeT (GenBase m)) a])
-> MaybeT (GenBase m) (NodeT (MaybeT (GenBase m)) [a])
interleave =
(forall (m :: * -> *) a. Monad m => [TreeT m a] -> m (NodeT m [a])
interleaveTreeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. NodeT m a -> a
nodeValue forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<)
in
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
sized forall a b. (a -> b) -> a -> b
$ \Size
size ->
forall (m :: * -> *) a. MonadGen m => (a -> Bool) -> m a -> m a
ensure (forall a. Int -> [a] -> Bool
atLeast forall a b. (a -> b) -> a -> b
$ forall a. Ord a => Size -> Range a -> a
Range.lowerBound Size
size Range Int
range) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (m :: * -> *) (n :: * -> *) a b.
(MonadGen m, MonadGen n) =>
(GenT (GenBase m) a -> GenT (GenBase n) b) -> m a -> n b
withGenT (forall (m :: * -> *) a (n :: * -> *) b.
(TreeT (MaybeT m) a -> TreeT (MaybeT n) b) -> GenT m a -> GenT n b
mapGenT (forall (m :: * -> *) a. m (NodeT m a) -> TreeT m a
TreeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {m :: * -> *} {a}.
MaybeT (GenBase m) (NodeT m [TreeT (MaybeT (GenBase m)) a])
-> MaybeT (GenBase m) (NodeT (MaybeT (GenBase m)) [a])
interleave forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. TreeT m a -> m (NodeT m a)
runTreeT)) forall a b. (a -> b) -> a -> b
$ do
Int
n <- forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral_ Range Int
range
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
n (forall (m :: * -> *) a.
MonadGen m =>
m a -> m (TreeT (MaybeT (GenBase m)) a)
toTreeMaybeT m a
gen)
interleaveTreeT :: Monad m => [TreeT m a] -> m (NodeT m [a])
interleaveTreeT :: forall (m :: * -> *) a. Monad m => [TreeT m a] -> m (NodeT m [a])
interleaveTreeT =
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (m :: * -> *) a. Monad m => [NodeT m a] -> NodeT m [a]
Tree.interleave forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall (m :: * -> *) a. TreeT m a -> m (NodeT m a)
runTreeT
seq :: MonadGen m => Range Int -> m a -> m (Seq a)
seq :: forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m (Seq a)
seq Range Int
range m a
gen =
forall a. [a] -> Seq a
Seq.fromList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
list Range Int
range m a
gen
nonEmpty :: MonadGen m => Range Int -> m a -> m (NonEmpty a)
nonEmpty :: forall (m :: * -> *) a.
MonadGen m =>
Range Int -> m a -> m (NonEmpty a)
nonEmpty Range Int
range m a
gen = do
[a]
xs <- forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
list (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. Ord a => a -> a -> a
max Int
1) Range Int
range) m a
gen
case [a]
xs of
[] ->
forall a. HasCallStack => String -> a
error String
"Hedgehog.Gen.nonEmpty: internal error, generated empty list"
[a]
_ ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. [a] -> NonEmpty a
NonEmpty.fromList [a]
xs
set :: (MonadGen m, Ord a) => Range Int -> m a -> m (Set a)
set :: forall (m :: * -> *) a.
(MonadGen m, Ord a) =>
Range Int -> m a -> m (Set a)
set Range Int
range m a
gen =
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall k a. Map k a -> Set k
Map.keysSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) k v.
(MonadGen m, Ord k) =>
Range Int -> m (k, v) -> m (Map k v)
map Range Int
range forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (, ()) m a
gen
map :: (MonadGen m, Ord k) => Range Int -> m (k, v) -> m (Map k v)
map :: forall (m :: * -> *) k v.
(MonadGen m, Ord k) =>
Range Int -> m (k, v) -> m (Map k v)
map Range Int
range m (k, v)
gen =
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
sized forall a b. (a -> b) -> a -> b
$ \Size
size ->
forall (m :: * -> *) a. MonadGen m => (a -> Bool) -> m a -> m a
ensure ((forall a. Ord a => a -> a -> Bool
>= forall a. Ord a => Size -> Range a -> a
Range.lowerBound Size
size Range Int
range) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Map k a -> Int
Map.size) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (m :: * -> *) a. MonadGen m => (a -> [a]) -> m a -> m a
shrink forall a. [a] -> [[a]]
Shrink.list forall a b. (a -> b) -> a -> b
$ do
Int
k <- forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral_ Range Int
range
forall (m :: * -> *) k v.
(MonadGen m, Ord k) =>
Int -> m (k, v) -> m [m (k, v)]
uniqueByKey Int
k m (k, v)
gen
uniqueByKey :: (MonadGen m, Ord k) => Int -> m (k, v) -> m [m (k, v)]
uniqueByKey :: forall (m :: * -> *) k v.
(MonadGen m, Ord k) =>
Int -> m (k, v) -> m [m (k, v)]
uniqueByKey Int
n m (k, v)
gen =
let
try :: Int -> Map k (m (k, v)) -> m [m (k, v)]
try Int
k Map k (m (k, v))
xs0 =
if Int
k forall a. Ord a => a -> a -> Bool
> Int
100 then
forall (m :: * -> *) a. MonadGen m => m a
discard
else
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
n (forall (m :: * -> *) a. MonadGen m => m a -> m (a, m a)
freeze m (k, v)
gen) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[((k, v), m (k, v))]
kvs ->
case forall k v.
Ord k =>
Int -> Map k v -> [(k, v)] -> Either (Map k v) (Map k v)
uniqueInsert Int
n Map k (m (k, v))
xs0 (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first forall a b. (a, b) -> a
fst) [((k, v), m (k, v))]
kvs) of
Left Map k (m (k, v))
xs ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [a]
Map.elems Map k (m (k, v))
xs
Right Map k (m (k, v))
xs ->
Int -> Map k (m (k, v)) -> m [m (k, v)]
try (Int
k forall a. Num a => a -> a -> a
+ Int
1) Map k (m (k, v))
xs
in
Int -> Map k (m (k, v)) -> m [m (k, v)]
try (Int
0 :: Int) forall k a. Map k a
Map.empty
uniqueInsert :: Ord k => Int -> Map k v -> [(k, v)] -> Either (Map k v) (Map k v)
uniqueInsert :: forall k v.
Ord k =>
Int -> Map k v -> [(k, v)] -> Either (Map k v) (Map k v)
uniqueInsert Int
n Map k v
xs [(k, v)]
kvs0 =
if forall k a. Map k a -> Int
Map.size Map k v
xs forall a. Ord a => a -> a -> Bool
>= Int
n then
forall a b. a -> Either a b
Left Map k v
xs
else
case [(k, v)]
kvs0 of
[] ->
forall a b. b -> Either a b
Right Map k v
xs
(k
k, v
v) : [(k, v)]
kvs ->
forall k v.
Ord k =>
Int -> Map k v -> [(k, v)] -> Either (Map k v) (Map k v)
uniqueInsert Int
n (forall k a. Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
Map.insertWith (\v
x v
_ -> v
x) k
k v
v Map k v
xs) [(k, v)]
kvs
atLeast :: Int -> [a] -> Bool
atLeast :: forall a. Int -> [a] -> Bool
atLeast Int
n =
if Int
n forall a. Eq a => a -> a -> Bool
== Int
0 then
forall a b. a -> b -> a
const Bool
True
else
Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> Bool
null forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> [a] -> [a]
drop (Int
n forall a. Num a => a -> a -> a
- Int
1)
data Subterms n a =
One a
| All (Vec n a)
deriving (forall a b. a -> Subterms n b -> Subterms n a
forall a b. (a -> b) -> Subterms n a -> Subterms n b
forall (n :: Nat) a b. a -> Subterms n b -> Subterms n a
forall (n :: Nat) a b. (a -> b) -> Subterms n a -> Subterms n b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Subterms n b -> Subterms n a
$c<$ :: forall (n :: Nat) a b. a -> Subterms n b -> Subterms n a
fmap :: forall a b. (a -> b) -> Subterms n a -> Subterms n b
$cfmap :: forall (n :: Nat) a b. (a -> b) -> Subterms n a -> Subterms n b
Functor, forall a. Subterms n a -> Bool
forall m a. Monoid m => (a -> m) -> Subterms n a -> m
forall a b. (a -> b -> b) -> b -> Subterms n a -> b
forall (n :: Nat) a. Eq a => a -> Subterms n a -> Bool
forall (n :: Nat) a. Num a => Subterms n a -> a
forall (n :: Nat) a. Ord a => Subterms n a -> a
forall (n :: Nat) m. Monoid m => Subterms n m -> m
forall (n :: Nat) a. Subterms n a -> Bool
forall (n :: Nat) a. Subterms n a -> Int
forall (n :: Nat) a. Subterms n a -> [a]
forall (n :: Nat) a. (a -> a -> a) -> Subterms n a -> a
forall (n :: Nat) m a. Monoid m => (a -> m) -> Subterms n a -> m
forall (n :: Nat) b a. (b -> a -> b) -> b -> Subterms n a -> b
forall (n :: Nat) a b. (a -> b -> b) -> b -> Subterms n a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => Subterms n a -> a
$cproduct :: forall (n :: Nat) a. Num a => Subterms n a -> a
sum :: forall a. Num a => Subterms n a -> a
$csum :: forall (n :: Nat) a. Num a => Subterms n a -> a
minimum :: forall a. Ord a => Subterms n a -> a
$cminimum :: forall (n :: Nat) a. Ord a => Subterms n a -> a
maximum :: forall a. Ord a => Subterms n a -> a
$cmaximum :: forall (n :: Nat) a. Ord a => Subterms n a -> a
elem :: forall a. Eq a => a -> Subterms n a -> Bool
$celem :: forall (n :: Nat) a. Eq a => a -> Subterms n a -> Bool
length :: forall a. Subterms n a -> Int
$clength :: forall (n :: Nat) a. Subterms n a -> Int
null :: forall a. Subterms n a -> Bool
$cnull :: forall (n :: Nat) a. Subterms n a -> Bool
toList :: forall a. Subterms n a -> [a]
$ctoList :: forall (n :: Nat) a. Subterms n a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Subterms n a -> a
$cfoldl1 :: forall (n :: Nat) a. (a -> a -> a) -> Subterms n a -> a
foldr1 :: forall a. (a -> a -> a) -> Subterms n a -> a
$cfoldr1 :: forall (n :: Nat) a. (a -> a -> a) -> Subterms n a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Subterms n a -> b
$cfoldl' :: forall (n :: Nat) b a. (b -> a -> b) -> b -> Subterms n a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Subterms n a -> b
$cfoldl :: forall (n :: Nat) b a. (b -> a -> b) -> b -> Subterms n a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Subterms n a -> b
$cfoldr' :: forall (n :: Nat) a b. (a -> b -> b) -> b -> Subterms n a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Subterms n a -> b
$cfoldr :: forall (n :: Nat) a b. (a -> b -> b) -> b -> Subterms n a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Subterms n a -> m
$cfoldMap' :: forall (n :: Nat) m a. Monoid m => (a -> m) -> Subterms n a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Subterms n a -> m
$cfoldMap :: forall (n :: Nat) m a. Monoid m => (a -> m) -> Subterms n a -> m
fold :: forall m. Monoid m => Subterms n m -> m
$cfold :: forall (n :: Nat) m. Monoid m => Subterms n m -> m
Foldable, forall (n :: Nat). Functor (Subterms n)
forall (n :: Nat). Foldable (Subterms n)
forall (n :: Nat) (m :: * -> *) a.
Monad m =>
Subterms n (m a) -> m (Subterms n a)
forall (n :: Nat) (f :: * -> *) a.
Applicative f =>
Subterms n (f a) -> f (Subterms n a)
forall (n :: Nat) (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Subterms n a -> m (Subterms n b)
forall (n :: Nat) (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Subterms n a -> f (Subterms n b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Subterms n a -> f (Subterms n b)
sequence :: forall (m :: * -> *) a.
Monad m =>
Subterms n (m a) -> m (Subterms n a)
$csequence :: forall (n :: Nat) (m :: * -> *) a.
Monad m =>
Subterms n (m a) -> m (Subterms n a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Subterms n a -> m (Subterms n b)
$cmapM :: forall (n :: Nat) (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Subterms n a -> m (Subterms n b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Subterms n (f a) -> f (Subterms n a)
$csequenceA :: forall (n :: Nat) (f :: * -> *) a.
Applicative f =>
Subterms n (f a) -> f (Subterms n a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Subterms n a -> f (Subterms n b)
$ctraverse :: forall (n :: Nat) (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Subterms n a -> f (Subterms n b)
Traversable)
data Nat =
Z
| S Nat
data Vec n a where
Nil :: Vec 'Z a
(:.) :: a -> Vec n a -> Vec ('S n) a
infixr 5 :.
deriving instance Functor (Vec n)
deriving instance Foldable (Vec n)
deriving instance Traversable (Vec n)
freeze :: MonadGen m => m a -> m (a, m a)
freeze :: forall (m :: * -> *) a. MonadGen m => m a -> m (a, m a)
freeze =
forall (m :: * -> *) (n :: * -> *) a b.
(MonadGen m, MonadGen n) =>
(GenT (GenBase m) a -> GenT (GenBase n) b) -> m a -> n b
withGenT forall a b. (a -> b) -> a -> b
$ \GenT (GenBase m) a
gen ->
forall (m :: * -> *) a.
(Size -> Seed -> TreeT (MaybeT m) a) -> GenT m a
GenT forall a b. (a -> b) -> a -> b
$ \Size
size Seed
seed -> do
Maybe (NodeT (MaybeT (GenBase m)) a)
mx <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. TreeT m a -> m (NodeT m a)
runTreeT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
Size -> Seed -> GenT m a -> TreeT (MaybeT m) a
runGenT Size
size Seed
seed GenT (GenBase m) a
gen
case Maybe (NodeT (MaybeT (GenBase m)) a)
mx of
Maybe (NodeT (MaybeT (GenBase m)) a)
Nothing ->
forall (f :: * -> *) a. Alternative f => f a
empty
Just (NodeT a
x [TreeT (MaybeT (GenBase m)) a]
xs) ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a
x, forall (m :: * -> *) a. MonadGen m => GenT (GenBase m) a -> m a
fromGenT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
MonadGen m =>
TreeT (MaybeT (GenBase m)) a -> m a
fromTreeMaybeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Applicative m => NodeT m a -> TreeT m a
Tree.fromNodeT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. a -> [TreeT m a] -> NodeT m a
NodeT a
x [TreeT (MaybeT (GenBase m)) a]
xs)
shrinkSubterms :: Subterms n a -> [Subterms n a]
shrinkSubterms :: forall (n :: Nat) a. Subterms n a -> [Subterms n a]
shrinkSubterms = \case
One a
_ ->
[]
All Vec n a
xs ->
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (n :: Nat) a. a -> Subterms n a
One forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> [a]
toList Vec n a
xs
genSubterms :: MonadGen m => Vec n (m a) -> m (Subterms n a)
genSubterms :: forall (m :: * -> *) (n :: Nat) a.
MonadGen m =>
Vec n (m a) -> m (Subterms n a)
genSubterms =
(forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (m :: * -> *) a. MonadGen m => (a -> [a]) -> m a -> m a
shrink forall (n :: Nat) a. Subterms n a -> [Subterms n a]
shrinkSubterms forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (n :: Nat) a. Vec n a -> Subterms n a
All forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadGen m => m a -> m (a, m a)
freeze)
fromSubterms :: Applicative m => (Vec n a -> m a) -> Subterms n a -> m a
fromSubterms :: forall (m :: * -> *) (n :: Nat) a.
Applicative m =>
(Vec n a -> m a) -> Subterms n a -> m a
fromSubterms Vec n a -> m a
f = \case
One a
x ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x
All Vec n a
xs ->
Vec n a -> m a
f Vec n a
xs
subtermMVec :: MonadGen m => Vec n (m a) -> (Vec n a -> m a) -> m a
subtermMVec :: forall (m :: * -> *) (n :: Nat) a.
MonadGen m =>
Vec n (m a) -> (Vec n a -> m a) -> m a
subtermMVec Vec n (m a)
gs Vec n a -> m a
f =
forall (m :: * -> *) (n :: Nat) a.
Applicative m =>
(Vec n a -> m a) -> Subterms n a -> m a
fromSubterms Vec n a -> m a
f forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *) (n :: Nat) a.
MonadGen m =>
Vec n (m a) -> m (Subterms n a)
genSubterms Vec n (m a)
gs
subtermM :: MonadGen m => m a -> (a -> m a) -> m a
subtermM :: forall (m :: * -> *) a. MonadGen m => m a -> (a -> m a) -> m a
subtermM m a
gx a -> m a
f =
forall (m :: * -> *) (n :: Nat) a.
MonadGen m =>
Vec n (m a) -> (Vec n a -> m a) -> m a
subtermMVec (m a
gx forall a (n :: Nat). a -> Vec n a -> Vec ('S n) a
:. forall a. Vec 'Z a
Nil) forall a b. (a -> b) -> a -> b
$ \(a
x :. Vec n a
Nil) ->
a -> m a
f a
x
subterm :: MonadGen m => m a -> (a -> a) -> m a
subterm :: forall (m :: * -> *) a. MonadGen m => m a -> (a -> a) -> m a
subterm m a
gx a -> a
f =
forall (m :: * -> *) a. MonadGen m => m a -> (a -> m a) -> m a
subtermM m a
gx forall a b. (a -> b) -> a -> b
$ \a
x ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> a
f a
x)
subtermM2 :: MonadGen m => m a -> m a -> (a -> a -> m a) -> m a
subtermM2 :: forall (m :: * -> *) a.
MonadGen m =>
m a -> m a -> (a -> a -> m a) -> m a
subtermM2 m a
gx m a
gy a -> a -> m a
f =
forall (m :: * -> *) (n :: Nat) a.
MonadGen m =>
Vec n (m a) -> (Vec n a -> m a) -> m a
subtermMVec (m a
gx forall a (n :: Nat). a -> Vec n a -> Vec ('S n) a
:. m a
gy forall a (n :: Nat). a -> Vec n a -> Vec ('S n) a
:. forall a. Vec 'Z a
Nil) forall a b. (a -> b) -> a -> b
$ \(a
x :. a
y :. Vec n a
Nil) ->
a -> a -> m a
f a
x a
y
subterm2 :: MonadGen m => m a -> m a -> (a -> a -> a) -> m a
subterm2 :: forall (m :: * -> *) a.
MonadGen m =>
m a -> m a -> (a -> a -> a) -> m a
subterm2 m a
gx m a
gy a -> a -> a
f =
forall (m :: * -> *) a.
MonadGen m =>
m a -> m a -> (a -> a -> m a) -> m a
subtermM2 m a
gx m a
gy forall a b. (a -> b) -> a -> b
$ \a
x a
y ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> a -> a
f a
x a
y)
subtermM3 :: MonadGen m => m a -> m a -> m a -> (a -> a -> a -> m a) -> m a
subtermM3 :: forall (m :: * -> *) a.
MonadGen m =>
m a -> m a -> m a -> (a -> a -> a -> m a) -> m a
subtermM3 m a
gx m a
gy m a
gz a -> a -> a -> m a
f =
forall (m :: * -> *) (n :: Nat) a.
MonadGen m =>
Vec n (m a) -> (Vec n a -> m a) -> m a
subtermMVec (m a
gx forall a (n :: Nat). a -> Vec n a -> Vec ('S n) a
:. m a
gy forall a (n :: Nat). a -> Vec n a -> Vec ('S n) a
:. m a
gz forall a (n :: Nat). a -> Vec n a -> Vec ('S n) a
:. forall a. Vec 'Z a
Nil) forall a b. (a -> b) -> a -> b
$ \(a
x :. a
y :. a
z :. Vec n a
Nil) ->
a -> a -> a -> m a
f a
x a
y a
z
subterm3 :: MonadGen m => m a -> m a -> m a -> (a -> a -> a -> a) -> m a
subterm3 :: forall (m :: * -> *) a.
MonadGen m =>
m a -> m a -> m a -> (a -> a -> a -> a) -> m a
subterm3 m a
gx m a
gy m a
gz a -> a -> a -> a
f =
forall (m :: * -> *) a.
MonadGen m =>
m a -> m a -> m a -> (a -> a -> a -> m a) -> m a
subtermM3 m a
gx m a
gy m a
gz forall a b. (a -> b) -> a -> b
$ \a
x a
y a
z ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> a -> a -> a
f a
x a
y a
z)
subsequence :: MonadGen m => [a] -> m [a]
subsequence :: forall (m :: * -> *) a. MonadGen m => [a] -> m [a]
subsequence [a]
xs =
forall (m :: * -> *) a. MonadGen m => (a -> [a]) -> m a -> m a
shrink forall a. [a] -> [[a]]
Shrink.list forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM (forall a b. a -> b -> a
const forall (m :: * -> *). MonadGen m => m Bool
bool_) [a]
xs
shuffle :: MonadGen m => [a] -> m [a]
shuffle :: forall (m :: * -> *) a. MonadGen m => [a] -> m [a]
shuffle = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (t :: * -> *) a. Foldable t => t a -> [a]
toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadGen m => Seq a -> m (Seq a)
shuffleSeq forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> Seq a
Seq.fromList
shuffleSeq :: MonadGen m => Seq a -> m (Seq a)
shuffleSeq :: forall (m :: * -> *) a. MonadGen m => Seq a -> m (Seq a)
shuffleSeq Seq a
xs =
if forall (t :: * -> *) a. Foldable t => t a -> Bool
null Seq a
xs then
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Seq a
Seq.empty
else do
Int
n <- forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
integral forall a b. (a -> b) -> a -> b
$ forall a. a -> a -> Range a
Range.constant Int
0 (forall (t :: * -> *) a. Foldable t => t a -> Int
length Seq a
xs forall a. Num a => a -> a -> a
- Int
1)
#if MIN_VERSION_containers(0,5,8)
case forall a. Int -> Seq a -> Maybe a
Seq.lookup Int
n Seq a
xs of
Just a
y ->
(a
y forall a. a -> Seq a -> Seq a
Seq.<|) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. MonadGen m => Seq a -> m (Seq a)
shuffleSeq (forall a. Int -> Seq a -> Seq a
Seq.deleteAt Int
n Seq a
xs)
Maybe a
Nothing ->
forall a. HasCallStack => String -> a
error String
"Hedgehog.Gen.shuffleSeq: internal error, lookup in empty sequence"
#else
case Seq.splitAt n xs of
(beginning, end) ->
case Seq.viewl end of
y Seq.:< end' ->
(y Seq.<|) <$> shuffleSeq (beginning Seq.>< end')
Seq.EmptyL ->
error "Hedgehog.Gen.shuffleSeq: internal error, lookup in empty sequence"
#endif
sample :: MonadIO m => Gen a -> m a
sample :: forall (m :: * -> *) a. MonadIO m => Gen a -> m a
sample Gen a
gen =
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
let
loop :: Int -> IO a
loop Int
n =
if Int
n forall a. Ord a => a -> a -> Bool
<= Int
0 then
forall a. HasCallStack => String -> a
error String
"Hedgehog.Gen.sample: too many discards, could not generate a sample"
else do
Seed
seed <- forall (m :: * -> *). MonadIO m => m Seed
Seed.random
case forall a. Size -> Seed -> Gen a -> Maybe (Tree a)
evalGen Size
30 Seed
seed Gen a
gen of
Maybe (Tree a)
Nothing ->
Int -> IO a
loop (Int
n forall a. Num a => a -> a -> a
- Int
1)
Just Tree a
x ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. Tree a -> a
Tree.treeValue Tree a
x
in
Int -> IO a
loop (Int
100 :: Int)
print :: (MonadIO m, Show a) => Gen a -> m ()
print :: forall (m :: * -> *) a. (MonadIO m, Show a) => Gen a -> m ()
print Gen a
gen = do
Seed
seed <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall (m :: * -> *). MonadIO m => m Seed
Seed.random
forall (m :: * -> *) a.
(MonadIO m, Show a) =>
Size -> Seed -> Gen a -> m ()
printWith Size
30 Seed
seed Gen a
gen
printWith :: (MonadIO m, Show a) => Size -> Seed -> Gen a -> m ()
printWith :: forall (m :: * -> *) a.
(MonadIO m, Show a) =>
Size -> Seed -> Gen a -> m ()
printWith Size
size Seed
seed Gen a
gen =
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
case forall a. Size -> Seed -> Gen a -> Maybe (Tree a)
evalGen Size
size Seed
seed Gen a
gen of
Maybe (Tree a)
Nothing -> do
String -> IO ()
putStrLn String
"=== Outcome ==="
String -> IO ()
putStrLn String
"<discard>"
Just Tree a
tree_ -> do
let
NodeT a
x [Tree a]
ss =
forall a. Identity a -> a
runIdentity (forall (m :: * -> *) a. TreeT m a -> m (NodeT m a)
runTreeT Tree a
tree_)
String -> IO ()
putStrLn String
"=== Outcome ==="
String -> IO ()
putStrLn (forall a. Show a => a -> String
show a
x)
String -> IO ()
putStrLn String
"=== Shrinks ==="
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ [Tree a]
ss forall a b. (a -> b) -> a -> b
$ \Tree a
s ->
let
NodeT a
y [Tree a]
_ =
forall a. Identity a -> a
runIdentity forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. TreeT m a -> m (NodeT m a)
runTreeT Tree a
s
in
String -> IO ()
putStrLn (forall a. Show a => a -> String
show a
y)
printTree :: (MonadIO m, Show a) => Gen a -> m ()
printTree :: forall (m :: * -> *) a. (MonadIO m, Show a) => Gen a -> m ()
printTree Gen a
gen = do
Seed
seed <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall (m :: * -> *). MonadIO m => m Seed
Seed.random
forall (m :: * -> *) a.
(MonadIO m, Show a) =>
Size -> Seed -> Gen a -> m ()
printTreeWith Size
30 Seed
seed Gen a
gen
printTreeWith :: (MonadIO m, Show a) => Size -> Seed -> Gen a -> m ()
printTreeWith :: forall (m :: * -> *) a.
(MonadIO m, Show a) =>
Size -> Seed -> Gen a -> m ()
printTreeWith Size
size Seed
seed Gen a
gen = do
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO ()
putStr forall a b. (a -> b) -> a -> b
$
forall a. Show a => Size -> Seed -> Gen a -> String
renderTree Size
size Seed
seed Gen a
gen
renderTree :: Show a => Size -> Seed -> Gen a -> String
renderTree :: forall a. Show a => Size -> Seed -> Gen a -> String
renderTree Size
size Seed
seed Gen a
gen =
case forall a. Size -> Seed -> Gen a -> Maybe (Tree a)
evalGen Size
size Seed
seed Gen a
gen of
Maybe (Tree a)
Nothing ->
String
"<discard>"
Just Tree a
x ->
Tree String -> String
Tree.render (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Show a => a -> String
show Tree a
x)