Copyright | (c) 2014 Aleksey Kliger |
---|---|
License | BSD3 (See LICENSE) |
Maintainer | Aleksey Kliger |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
A typeclass for types that may participate in capture-avoiding substitution
The minimal definition is empty, provided your type is an instance of Generic
type Var = Name Factor data Expr = SumOf [Summand] deriving (Show, Generic) data Summand = ProductOf [Factor] deriving (Show, Generic) instance Subst Var Expr instance Subst Var Summand
The default instance just propagates the substitution into the constituent factors.
If you identify the variable occurrences by implementing the isvar
function, the derived subst
function
will be able to substitute a factor for a variable.
data Factor = V Var | C Int | Subexpr Expr deriving (Show, Generic) instance Subst Var Factor where isvar (V v) = Just (SubstName v) isvar _ = Nothing
Synopsis
- data SubstName a b where
- data SubstCoerce a b where
- SubstCoerce :: Name b -> (b -> Maybe a) -> SubstCoerce a b
- class Subst b a where
- isvar :: a -> Maybe (SubstName a b)
- isCoerceVar :: a -> Maybe (SubstCoerce a b)
- subst :: Name b -> b -> a -> a
- substs :: [(Name b, b)] -> a -> a
Documentation
data SubstCoerce a b where Source #
See isCoerceVar
SubstCoerce :: Name b -> (b -> Maybe a) -> SubstCoerce a b |
class Subst b a where Source #
Instances of
are terms of type Subst
b aa
that may contain
variables of type b
that may participate in capture-avoiding
substitution.
Nothing
isvar :: a -> Maybe (SubstName a b) Source #
This is the only method that must be implemented
isCoerceVar :: a -> Maybe (SubstCoerce a b) Source #
This is an alternative version to isvar
, useable in the case
that the substituted argument doesn't have *exactly* the same type
as the term it should be substituted into.
The default implementation always returns Nothing
.
subst :: Name b -> b -> a -> a Source #
substitutes subst
nm e tme
for nm
in tm
. It has
a default generic implementation in terms of isvar
subst :: (Generic a, GSubst b (Rep a)) => Name b -> b -> a -> a Source #
substitutes subst
nm e tme
for nm
in tm
. It has
a default generic implementation in terms of isvar
substs :: [(Name b, b)] -> a -> a Source #
substs :: (Generic a, GSubst b (Rep a)) => [(Name b, b)] -> a -> a Source #