ho-rewriting-0.2: Generic rewrite rules with safe treatment of variables and binders

Safe HaskellNone
LanguageHaskell2010

Data.Rewriting.Rules

Contents

Description

Rewrite rules

Synopsis

Tagless rewrite rules

data Rule lhs rhs where Source

Rewrite rules

Constructors

Rule :: lhs a -> rhs a -> Rule lhs rhs 

Instances

Quantifiable (Rule lhs rhs) Source

Base case: no meta-variables

type RuleType (Rule lhs rhs) = Rule lhs rhs Source 

(===>) :: lhs a -> rhs a -> Rule lhs rhs infix 1 Source

Construct a rule from an LHS and an RHS

class WildCard r where Source

Representations supporting wildcards

Minimal complete definition

Nothing

Methods

__ :: r a Source

Instances

data MetaExp r a where Source

Meta-variable applied to a number of Var expressions

Constructors

MVar :: MetaRep r a -> MetaExp r a 
MApp :: MetaExp r (a -> b) -> MetaArg r a -> MetaExp r b 

class MetaVar r where Source

Representations supporting meta-variables

Associated Types

type MetaRep r :: * -> * Source

type MetaArg r :: * -> * Source

Methods

metaExp :: MetaExp r a -> r a Source

Instances

meta :: MetaVar r => MetaRep r a -> r a Source

Construct a meta-variable

($$) :: MetaExp r (a -> b) -> MetaArg r a -> MetaExp r b infixl 2 Source

Meta-variable application (used for all but the first and last variable)

($-) :: MetaVar r => MetaExp r (a -> b) -> MetaArg r a -> r b infixl 2 Source

Meta-variable application (used for the last variable)

(-$) :: MetaRep r (a -> b) -> MetaArg r a -> MetaExp r b infixl 2 Source

Meta-variable application (used for the first variable)

(-$-) :: MetaVar r => MetaRep r (a -> b) -> MetaArg r a -> r b infixl 2 Source

Meta-variable application (used when there is only variable)

type Name = Integer Source

Variable identifier

newtype MetaId a Source

Typed meta-variable identifiers

Constructors

MetaId Name 

class Quantifiable rule where Source

Rules that may take a number of meta-variables as arguments. Those meta-variables are implicitly forall-quantified.

Associated Types

type RuleType rule Source

Rule type after quantification

Methods

quantify' :: Name -> rule -> RuleType rule Source

Quantify a rule starting from the provided variable identifier

Instances

(Quantifiable rule, (~) * m (MetaId a)) => Quantifiable (m -> rule) Source

Recursive case: one more meta-variable

Quantifiable (Rule lhs rhs) Source

Base case: no meta-variables

quantify :: (Quantifiable rule, RuleType rule ~ Rule lhs rhs) => rule -> Rule lhs rhs Source

Forall-quantify the meta-variable arguments of a rule

Representation of rules

data WILD a Source

Functor representing wildcards

Constructors

WildCard 

data META r a Source

Functor representing meta variables applied to a number of Var expressions

Constructors

forall b . Meta (MetaExp r b) 

newtype LHS f a Source

Left hand side of a rule

Constructors

LHS 

Fields

unLHS :: Term (WILD :+: (META (LHS f) :+: f))
 

Instances

Rep (LHS f) Source 
MetaVar (LHS f) Source 
WildCard (LHS f) Source 
((:<:) VAR (PF (LHS f)), (:<:) LAM (PF (LHS f)), Functor f, Foldable f) => Bind (LHS f) Source 
type PF (LHS f) = (:+:) * WILD ((:+:) * (META (LHS f)) f) Source 
type Var (LHS f) = VAR Source 
type MetaRep (LHS f) = MetaId Source 
type MetaArg (LHS f) = Var (LHS f) Source 

newtype RHS f a Source

Right hand side of a rule

Constructors

RHS 

Fields

unRHS :: Term (META (RHS f) :+: f)
 

Instances

Rep (RHS f) Source 
MetaVar (RHS f) Source 
((:<:) VAR (PF (RHS f)), (:<:) LAM (PF (RHS f)), Functor f, Foldable f) => Bind (RHS f) Source 
type PF (RHS f) = (:+:) * (META (RHS f)) f Source 
type Var (RHS f) = VAR Source 
type MetaRep (RHS f) = MetaId Source 
type MetaArg (RHS f) = RHS f Source 

type family Var r :: * -> * Source

Representation of object variables

Instances

type Var (RHS f) = VAR Source 
type Var (LHS f) = VAR Source 

Generalize over representations

class Rep r where Source

Associated Types

type PF r :: * -> * Source

Methods

toRep :: Term (PF r) -> r a Source

fromRep :: r a -> Term (PF r) Source

Instances

Rep (RHS f) Source 
Rep (LHS f) Source 

Misc.

tRule :: Patch (Rule (LHS f) (RHS f)) (Rule (LHS f) (RHS f)) Source

data A Source

Constructors

A 

Instances

data B Source

Constructors

B 

Instances

data C Source

Constructors

C 

Instances

type Subst f = [(Name, Term f)] Source

Substitution