unbound-0.4.4: Generic support for programming with names and binders

LicenseBSD-like (see LICENSE)
MaintainerBrent Yorgey <byorgey@cis.upenn.edu>
PortabilityGHC only (-XKitchenSink)
Safe HaskellNone
LanguageHaskell2010

Unbound.LocallyNameless.Subst

Description

The Subst type class for generic capture-avoiding substitution.

Synopsis

Documentation

data SubstName a b where Source

See isvar.

Constructors

SubstName :: (a ~ b) => Name a -> SubstName a b 

data SubstCoerce a b where Source

Constructors

SubstCoerce :: Name b -> (b -> Maybe a) -> SubstCoerce a b 

class Rep1 (SubstD b) a => Subst b a where Source

The Subst class governs capture-avoiding substitution. To derive this class, you only need to indicate where the variables are in the data type, by overriding the method isvar.

Minimal complete definition

Nothing

Methods

isvar :: a -> Maybe (SubstName a b) Source

This is the only method which normally needs to be implemented explicitly. If the argument is a variable, return its name wrapped in the SubstName constructor. Return Nothing for non-variable arguments. The default implementation always returns Nothing.

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

subst nm sub tm substitutes sub for nm in tm. It has a default generic implementation in terms of isvar.

substs :: [(Name b, b)] -> a -> a Source

Perform several simultaneous substitutions. This method also has a default generic implementation in terms of isvar.

Instances

Subst b AnyName Source 
Subst b Double Source 
Subst b Float Source 
Subst b Integer Source 
Subst b Char Source 
Subst b () Source 
Subst b Bool Source 
Subst b Int Source 
(Alpha a, Subst c a) => Subst c (Rec a) Source 
Subst c a => Subst c (Embed a) Source 
Subst c a => Subst c (Shift a) Source 
Subst c a => Subst c (Maybe a) Source 
Subst c a => Subst c [a] Source 
Rep a => Subst b (Name a) Source 
Rep a => Subst b (R a) Source 
(Subst c b, Subst c a, Alpha a, Alpha b) => Subst c (Rebind a b) Source 
(Subst c a, Subst c b) => Subst c (Either a b) Source 
(Subst c a, Subst c b) => Subst c (a, b) Source 
(Subst c a, Subst c b, Subst c d) => Subst c (a, b, d) Source 
(Rep order, Rep card, Subst c b, Subst c a, Alpha a, Alpha b) => Subst c (GenBind order card a b) Source 
(Subst c a, Subst c b, Subst c d, Subst c e) => Subst c (a, b, d, e) Source 
(Subst c a, Subst c b, Subst c d, Subst c e, Subst c f) => Subst c (a, b, d, e, f) Source 

data SubstD b a Source

Reified class dictionary for Subst.

Constructors

SubstD 

Fields

isvarD :: a -> Maybe (SubstName a b)
 
substD :: Name b -> b -> a -> a
 
substsD :: [(Name b, b)] -> a -> a
 

Instances

Subst b a => Sat (SubstD b a) Source 

substDefault :: Rep1 (SubstD b) a => Name b -> b -> a -> a Source

substR1 :: R1 (SubstD b) a -> Name b -> b -> a -> a Source

substsR1 :: R1 (SubstD b) a -> [(Name b, b)] -> a -> a Source