cryptol-3.5.0: Cryptol: The Language of Cryptography
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cryptol.TypeCheck.Subst.Type

Description

Most of this module is re-exported by Cryptol.TypeCheck.Subst, so you probably want to import that instead of this.

The exception being, if you want to substitute types without performing simplification afterwards, then you should use apSubstNoSimp from this module. It is in this module so that you can use it from places like the typeclass solver itself, to avoid a module import cycle (since the regular apSubst has to import the class solver to do the substitution).

Synopsis

Documentation

data Subst Source #

A Subst value represents a substitution that maps each TVar to a Type.

Invariant 1: If there is a mapping from TVFree _ _ tps _ to a type t, then t must not mention (directly or indirectly) any type parameter that is not in tps. In particular, if t contains a variable TVFree _ _ tps2 _, then tps2 must be a subset of tps. This ensures that applying the substitution will not permit any type parameter to escape from its scope.

Invariant 2: The substitution must be idempotent, in that applying a substitution to any Type in the map should leave that Type unchanged. In other words, Type values in the range of a Subst should not mention any TVar in the domain of the Subst. In particular, this implies that a substitution must not contain any recursive variable mappings.

Invariant 3: The substitution must be kind correct: Each TVar in the substitution must map to a Type of the same kind.

Constructors

S 

Instances

Instances details
Show Subst Source # 
Instance details

Defined in Cryptol.TypeCheck.Subst.Type

Methods

showsPrec :: Int -> Subst -> ShowS #

show :: Subst -> String #

showList :: [Subst] -> ShowS #

PP Subst Source # 
Instance details

Defined in Cryptol.TypeCheck.Subst.Type

Methods

ppPrec :: Int -> Subst -> Doc Source #

ppPrecWithAnnot :: [([Int], PPAnnot)] -> Int -> Subst -> Doc Source #

PP (WithNames Subst) Source # 
Instance details

Defined in Cryptol.TypeCheck.Subst.Type

data SubstError Source #

Reasons to reject a single-variable substitution.

Constructors

SubstRecursive

TVar maps to a type containing the same variable.

SubstEscaped [TParam]

TVar maps to a type containing one or more out-of-scope bound variables.

SubstKindMismatch Kind Kind

TVar maps to a type with a different kind.

defaultingSubst :: Subst -> Subst Source #

A defaulting substitution maps all otherwise-unmapped free variables to a kind-appropriate default type (Bit for value types and 0 for numeric types).

listSubst :: [(TVar, Type)] -> Subst Source #

Makes a substitution out of a list. WARNING: We do not validate the list in any way, so the caller should ensure that we end up with a valid (e.g., idempotent) substitution.

listParamSubst :: [(TParam, Type)] -> Subst Source #

Makes a substitution out of a list. WARNING: We do not validate the list in any way, so the caller should ensure that we end up with a valid (e.g., idempotent) substitution.

apSubstMaybe' :: (Prop -> Prop) -> Subst -> Type -> Maybe Type Source #

Apply a substitution. Returns Nothing if nothing changed. The Prop -> Prop function is how to simplify the result if it is a predicate.

apSubstNoSimp :: Subst -> Type -> Type Source #

Apply a substitution without simplifying the result when it is a predicate.

This is used by the typeclass solver itself, if it needs to perform substitution; e.g., when solving derived instances for nominal types. Some code asks the typeclass solver to do only a single simplification step; if it called the regular apSubst which simplifies recursively after substitution, then it would do many simplification steps instead of one, resulting in worse error messages. Not doing simplification also allows us to avoid a module dependency cycle.