Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains a definition of substitutions for expressions and type expressions.
Synopsis
- data Subst a
- identitySubst :: Subst a
- singleSubst :: QName -> a -> Subst a
- singleSubst' :: QName -> (SrcSpan -> a) -> Subst a
- mkVarSubst :: QName -> QName -> Subst Expr
- mkTypeVarSubst :: String -> String -> Subst Type
- composeSubst :: ApplySubst a a => Subst a -> Subst a -> Subst a
- composeSubsts :: ApplySubst a a => [Subst a] -> Subst a
- filterSubst :: (QName -> Bool) -> Subst a -> Subst a
- substWithout :: Subst a -> [QName] -> Subst a
- class ApplySubst a b where
- applySubst :: Subst a -> b -> b
- renameTypeArgsSubst :: [TypeVarDecl] -> Converter ([TypeVarDecl], Subst Type)
- renameTypeArgs :: ApplySubst Type a => [TypeVarDecl] -> a -> Converter ([TypeVarDecl], a)
- renameArgsSubst :: [VarPat] -> Converter ([VarPat], Subst Expr)
- renameArgs :: ApplySubst Expr a => [VarPat] -> a -> Converter ([VarPat], a)
Substitutions
A substitution is a mapping from Haskell variable names to expressions
(i.e.
) or type expressions (i.e. Subst
Expr
).Subst
Type
When the substitution is applied (see applySubst
), the source span of
the substituted variable can be inserted into the (type) expression it is
replaced by (e.g. to rename a variable without loosing source spans).
Construction
identitySubst :: Subst a Source #
A substitution that does not change an expression.
singleSubst :: QName -> a -> Subst a Source #
Creates a new substitution that maps the variable with the given name to the given expression or type expression.
singleSubst' :: QName -> (SrcSpan -> a) -> Subst a Source #
Like singleSubst
, but can be used to preserve the source span of the
variable replaced by applySubst
.
mkVarSubst :: QName -> QName -> Subst Expr Source #
Creates a substitution that renames variables with the given name and preserves source span information of the renamed variable.
mkTypeVarSubst :: String -> String -> Subst Type Source #
Creates a substitution that renames type variables with the given name and preserves source span information of the renamed type variable.
Composition
composeSubst :: ApplySubst a a => Subst a -> Subst a -> Subst a Source #
Creates a new substitution that applies both given substitutions after each other.
composeSubsts :: ApplySubst a a => [Subst a] -> Subst a Source #
Creates a new substitution that applies all given substitutions after each other.
Modification
filterSubst :: (QName -> Bool) -> Subst a -> Subst a Source #
Creates a new substitution whose domain does not contain the names that match the given predicate.
substWithout :: Subst a -> [QName] -> Subst a Source #
Creates a new substitution whose domain does not contain the given names.
Application
class ApplySubst a b where Source #
Type class for applying a substitution that replaces variables by
values of type a
on values of type b
.
applySubst :: Subst a -> b -> b Source #
Instances
ApplySubst Type Type Source # | Applies the given type substitution to a type expression. |
Defined in FreeC.IR.Subst | |
ApplySubst Type TypeScheme Source # | Applies the given type substitution to a type scheme. |
Defined in FreeC.IR.Subst applySubst :: Subst Type -> TypeScheme -> TypeScheme Source # | |
ApplySubst Type Bind Source # | Applies the given type substitution to the variable pattern and expression
of the given |
Defined in FreeC.IR.Subst | |
ApplySubst Type VarPat Source # | Applies the given type substitution to the type annotation of the given variable pattern. |
Defined in FreeC.IR.Subst | |
ApplySubst Type Alt Source # | Applies the given type substitution to the right-hand side of the
given |
Defined in FreeC.IR.Subst | |
ApplySubst Type Expr Source # | Applies the given type substitution to an expression. |
Defined in FreeC.IR.Subst | |
ApplySubst Type FuncDecl Source # | Applies the given type substitution to the right-hand side of a function declaration. |
Defined in FreeC.IR.Subst | |
ApplySubst Expr Bind Source # | Applies the given expression substitution to an the right-hand side of a
The variable that is bound by the binding is not renamed by this instance.
The |
Defined in FreeC.IR.Subst | |
ApplySubst Expr Alt Source # | Applies the given expression substitution to the right-hand side of the
given |
Defined in FreeC.IR.Subst | |
ApplySubst Expr Expr Source # | Applies the given expression substitution to an expression. This function uses the |
Defined in FreeC.IR.Subst | |
ApplySubst Expr FuncDecl Source # | Applies the given expression substitution to the right-hand side of a function declaration. |
Defined in FreeC.IR.Subst | |
(ApplySubst a b, Functor f) => ApplySubst a (f b) Source # | Substitutions can be applied to the elements of every functor. |
Defined in FreeC.IR.Subst applySubst :: Subst a -> f b -> f b Source # |
Rename Arguments
renameTypeArgsSubst :: [TypeVarDecl] -> Converter ([TypeVarDecl], Subst Type) Source #
Creates a substitution that renames the given type variables to fresh variables.
Returns the new names for the type variables and the substitution.
renameTypeArgs :: ApplySubst Type a => [TypeVarDecl] -> a -> Converter ([TypeVarDecl], a) Source #
Renames the given type variables in the given expression or type to fresh type variables.
renameArgsSubst :: [VarPat] -> Converter ([VarPat], Subst Expr) Source #
Creates a substitution that renames the arguments bound by the given variable patterns to fresh variables.
Returns the new names for the variables and the substitution.
renameArgs :: ApplySubst Expr a => [VarPat] -> a -> Converter ([VarPat], a) Source #
Renames the arguments bound by the given variable patterns in the given expression to fresh variables.
Returns the new names for the variables and the resulting expression.