Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- type GenTm = GenT (Reader GenEnv)
- data GenEnv = GenEnv {
- geAstSize ∷ Int
- geDatas ∷ Map TyName (Datatype TyName Name DefaultUni ())
- geTypes ∷ TypeCtx
- geTerms ∷ Map Name (Type TyName DefaultUni ())
- geUnboundUsedTyNames ∷ Set TyName
- geEscaping ∷ AllowEscape
- geCustomGen ∷ Maybe (Type TyName DefaultUni ()) → GenTm (Type TyName DefaultUni (), Term TyName Name DefaultUni DefaultFun ())
- geCustomFreq ∷ Int
- geDebug ∷ Bool
- suchThatMap ∷ Monad m ⇒ GenT m a → (a → Maybe b) → GenT m b
- withDebug ∷ GenTm a → GenTm a
- runGenTm ∷ GenTm a → Gen a
- runGenTmCustom ∷ Int → (Maybe (Type TyName DefaultUni ()) → GenTm (Type TyName DefaultUni (), Term TyName Name DefaultUni DefaultFun ())) → GenTm a → Gen a
- deliver ∷ Monad m ⇒ GenT m (Maybe a) → GenT m a
- withNoEscape ∷ GenTm a → GenTm a
- onAstSize ∷ (Int → Int) → GenTm a → GenTm a
- ifAstSizeZero ∷ GenTm a → GenTm a → GenTm a
- withAstSize ∷ Int → GenTm a → GenTm a
- astSizeSplit_ ∷ Int → Int → GenTm a → GenTm b → GenTm (a, b)
- astSizeSplit ∷ Int → Int → GenTm a → (a → GenTm b) → GenTm (a, b)
- getUniques ∷ GenTm (Set Unique)
- genLikelyFreshName ∷ String → GenTm Name
- genLikelyFreshNames ∷ [String] → GenTm [Name]
- genLikelyFreshTyName ∷ String → GenTm TyName
- genLikelyFreshTyNames ∷ [String] → GenTm [TyName]
- genLikelyNotFreshName ∷ String → GenTm Name
- genMaybeFreshName ∷ String → GenTm Name
- genMaybeFreshTyName ∷ String → GenTm TyName
- bindTyName ∷ TyName → Kind () → GenTm a → GenTm a
- bindTyNames ∷ [(TyName, Kind ())] → GenTm a → GenTm a
- registerTyName ∷ TyName → GenTm a → GenTm a
- bindTmName ∷ Name → Type TyName DefaultUni () → GenTm a → GenTm a
- bindTmNames ∷ [(Name, Type TyName DefaultUni ())] → GenTm a → GenTm a
- bindLikelyFreshTmName ∷ String → Type TyName DefaultUni () → (Name → GenTm a) → GenTm a
- bindDat ∷ Datatype TyName Name DefaultUni () → GenTm a → GenTm a
- bindBind ∷ Binding TyName Name DefaultUni DefaultFun () → GenTm a → GenTm a
- bindBinds ∷ Foldable f ⇒ f (Binding TyName Name DefaultUni DefaultFun ()) → GenTm a → GenTm a
- class (Applicative g, Monad g) ⇒ MonadGen (g ∷ Type → Type) where
- newtype GenT (m ∷ Type → Type) a = GenT {}
- runGenT ∷ GenT m a → Gen (m a)
- frequency ∷ MonadGen m ⇒ [(Int, m a)] → m a
- suchThat ∷ MonadGen m ⇒ m a → (a → Bool) → m a
- suchThatMaybe ∷ MonadGen m ⇒ m a → (a → Bool) → m (Maybe a)
- listOf ∷ MonadGen m ⇒ m a → m [a]
- listOf1 ∷ MonadGen m ⇒ m a → m [a]
- vectorOf ∷ MonadGen m ⇒ Int → m a → m [a]
- oneof ∷ MonadGen m ⇒ [m a] → m a
- elements ∷ MonadGen m ⇒ [a] → m a
- growingElements ∷ MonadGen m ⇒ [a] → m a
- oneofMay ∷ MonadGen m ⇒ [m a] → m (Maybe a)
- elementsMay ∷ MonadGen m ⇒ [a] → m (Maybe a)
- growingElementsMay ∷ MonadGen m ⇒ [a] → m (Maybe a)
- class Arbitrary a where
- data Gen a
Documentation
type GenTm = GenT (Reader GenEnv) Source #
Term generators carry around a context to know e.g. what types and terms are in scope.
GenEnv | |
|
suchThatMap ∷ Monad m ⇒ GenT m a → (a → Maybe b) → GenT m b Source #
Create a generator that runs the given generator and applies the given function to produced
values until the result is a Just y
, returning the y
.
runGenTm ∷ GenTm a → Gen a Source #
Run a `GenTm generator in a top-level empty context where we are allowed to generate datatypes.
runGenTmCustom ∷ Int → (Maybe (Type TyName DefaultUni ()) → GenTm (Type TyName DefaultUni (), Term TyName Name DefaultUni DefaultFun ())) → GenTm a → Gen a Source #
Run a GenTm
generator with a plug-in custom generator for terms that is included with
the other generators.
deliver ∷ Monad m ⇒ GenT m (Maybe a) → GenT m a Source #
Create a generator that runs the given generator until the result is a Just x
,
returning the x
.
withNoEscape ∷ GenTm a → GenTm a Source #
Don't allow types to escape from a generator.
ifAstSizeZero ∷ GenTm a → GenTm a → GenTm a Source #
Default to the first generator if the size is zero (or negative), use the second generator otherwise.
astSizeSplit_ ∷ Int → Int → GenTm a → GenTm b → GenTm (a, b) Source #
Split the size between two generators in the ratio specified by the first two arguments.
astSizeSplit ∷ Int → Int → GenTm a → (a → GenTm b) → GenTm (a, b) Source #
Split the size between two generators in the ratio specified by the first two arguments and use the result of the first generator in the second.
getUniques ∷ GenTm (Set Unique) Source #
Get all uniques we have generated and are used in the current context.
genLikelyFreshName ∷ String → GenTm Name Source #
Generate a likely fresh name. See Note [Warning about generating fresh names].
genLikelyFreshNames ∷ [String] → GenTm [Name] Source #
Generate one likely fresh name per string in the input list.
Note that this may not give you a fresh name, if it happens to generate a name that was removed
from the terms map in bindTyName
(due to referencing a now-shadowed type variable) but is still
in the scope.
genLikelyFreshTyName ∷ String → GenTm TyName Source #
Same as genLikelyFreshName
, except gives you a TyName
.
genLikelyFreshTyNames ∷ [String] → GenTm [TyName] Source #
Same as genLikelyFreshNames
, except gives you TyName
s.
genLikelyNotFreshName ∷ String → GenTm Name Source #
Generate a name that likely overlaps with existing names on purpose. If there are no existing
names, generate a fresh name. This function doesn't distinguish between the type- and term-level
scopes, hence it may generate a Name
"clashing" with a previously generated TyName
and not
clashing with any previously generated Name
. Which is a good thing, because we want to check
that Plutus is able to handle such spurious name clashes. Generating weird stuff is useful for a
testing machinery! We don't need any "definitely non-fresh name" anyway, since we get enough
non-fresh names already.
genMaybeFreshName ∷ String → GenTm Name Source #
Generate a fresh name most (roughly 75%) of the time and otherwise generate an already bound name. When there are no bound names generate a fresh name.
bindTyName ∷ TyName → Kind () → GenTm a → GenTm a Source #
Bind a type name to a kind and avoid capturing free type variables.
registerTyName ∷ TyName → GenTm a → GenTm a Source #
Remember that we have generated a type name locally but don't bind it. Useful for non-recursive definitions where we want to control name overlap.
bindTmName ∷ Name → Type TyName DefaultUni () → GenTm a → GenTm a Source #
Bind a term to a type in a generator.
bindTmNames ∷ [(Name, Type TyName DefaultUni ())] → GenTm a → GenTm a Source #
Bind term names
bindLikelyFreshTmName ∷ String → Type TyName DefaultUni () → (Name → GenTm a) → GenTm a Source #
Create a fresh term name, bind it to a type, and use it in a generator.
bindDat ∷ Datatype TyName Name DefaultUni () → GenTm a → GenTm a Source #
Bind a datatype declaration in a generator.
bindBind ∷ Binding TyName Name DefaultUni DefaultFun () → GenTm a → GenTm a Source #
Bind a binding.
bindBinds ∷ Foldable f ⇒ f (Binding TyName Name DefaultUni DefaultFun ()) → GenTm a → GenTm a Source #
Bind multiple bindings
class (Applicative g, Monad g) ⇒ MonadGen (g ∷ Type → Type) where Source #
liftGen ∷ Gen a → g a Source #
variant ∷ Integral n ⇒ n → g a → g a Source #
sized ∷ (Int → g a) → g a Source #
frequency ∷ MonadGen m ⇒ [(Int, m a)] → m a Source #
Chooses one of the given generators, with a weighted random distribution. The input list must be non-empty.
suchThat ∷ MonadGen m ⇒ m a → (a → Bool) → m a Source #
Generates a value that satisfies a predicate.
suchThatMaybe ∷ MonadGen m ⇒ m a → (a → Bool) → m (Maybe a) Source #
Tries to generate a value that satisfies a predicate.
listOf ∷ MonadGen m ⇒ m a → m [a] Source #
Generates a list of random length. The maximum length depends on the size parameter.
listOf1 ∷ MonadGen m ⇒ m a → m [a] Source #
Generates a non-empty list of random length. The maximum length depends on the size parameter.
oneof ∷ MonadGen m ⇒ [m a] → m a Source #
Randomly uses one of the given generators. The input list must be non-empty.
elements ∷ MonadGen m ⇒ [a] → m a Source #
Generates one of the given values. The input list must be non-empty.
growingElements ∷ MonadGen m ⇒ [a] → m a Source #
Takes a list of elements of increasing size, and chooses among an initial segment of the list. The size of this initial segment increases with the size parameter. The input list must be non-empty.
elementsMay ∷ MonadGen m ⇒ [a] → m (Maybe a) Source #
Generates one of the given values.
growingElementsMay ∷ MonadGen m ⇒ [a] → m (Maybe a) Source #
Takes a list of elements of increasing size, and chooses among an initial segment of the list. The size of this initial segment increases with the size parameter.