free-compiler-0.3.0.0: A Haskell to Coq compiler.

Safe HaskellNone
LanguageHaskell2010

FreeC.IR.Subst

Contents

Description

This module contains a definition of substitutions for expressions and type expressions.

Synopsis

Substitutions

data Subst a Source #

A substitution is a mapping from Haskell variable names to expressions (i.e. Subst Expr) or type expressions (i.e. 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).

Instances
Pretty a => Pretty (Subst a) Source #

Substitutions can be pretty printed for testing purposes.

Instance details

Defined in FreeC.IR.Subst

Methods

pretty :: Subst a -> Doc #

prettyList :: [Subst a] -> Doc #

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.

Methods

applySubst :: Subst a -> b -> b Source #

Instances
ApplySubst Type Type Source #

Applies the given type substitution to a type expression.

Instance details

Defined in FreeC.IR.Subst

ApplySubst Type TypeScheme Source #

Applies the given type substitution to a type scheme.

Instance details

Defined in FreeC.IR.Subst

ApplySubst Type Bind Source #

Applies the given type substitution to the variable pattern and expression of the given let binding.

Instance details

Defined in FreeC.IR.Subst

ApplySubst Type VarPat Source #

Applies the given type substitution to the type annotation of the given variable pattern.

Instance details

Defined in FreeC.IR.Subst

ApplySubst Type Alt Source #

Applies the given type substitution to the right-hand side of the given case-expression alternative.

Instance details

Defined in FreeC.IR.Subst

Methods

applySubst :: Subst Type -> Alt -> Alt Source #

ApplySubst Type Expr Source #

Applies the given type substitution to an expression.

Instance details

Defined in FreeC.IR.Subst

ApplySubst Type FuncDecl Source #

Applies the given type substitution to the right-hand side of a function declaration.

Instance details

Defined in FreeC.IR.Subst

ApplySubst Expr Bind Source #

Applies the given expression substitution to an the right-hand side of a let binding.

The variable that is bound by the binding is not renamed by this instance. The ApplySubst instance for expressions renames all variables that are bound by let expressions.

Instance details

Defined in FreeC.IR.Subst

ApplySubst Expr Alt Source #

Applies the given expression substitution to the right-hand side of the given case-expression alternative.

Instance details

Defined in FreeC.IR.Subst

Methods

applySubst :: Subst Expr -> Alt -> Alt Source #

ApplySubst Expr Expr Source #

Applies the given expression substitution to an expression.

This function uses the Converter monad, because we need to create fresh identifiers. This is because we have to rename arguments of lambda abstractions and case-alternatives, such that no name conflict can occur.

Instance details

Defined in FreeC.IR.Subst

ApplySubst Expr FuncDecl Source #

Applies the given expression substitution to the right-hand side of a function declaration.

Instance details

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.

Instance details

Defined in FreeC.IR.Subst

Methods

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.