rewriting-0.2.2: Generic rewriting library for regular datatypes.

Portabilitynon-portable
Stabilityexperimental
Maintainergenerics@haskell.org
Safe HaskellSafe-Infered

Generics.Regular.Rewriting.Rules

Contents

Description

Summary: Functions for transforming a rule specification to a rule.

Synopsis

Rule specification.

data RuleSpec a Source

Specifies a rule as a value of a datatype.

Constructors

a :~> a 

Instances

lhsR :: RuleSpec a -> aSource

Returns the left-hand side of a rule.

rhsR :: RuleSpec a -> aSource

Returns the right-hand side of a rule.

Representation of a rule.

type Rule a = RuleSpec (SchemeOf a)Source

Allows metavariables on either side of a rule.

type SchemeOf a = Scheme (PF a)Source

Extends the pattern functor of a value.

metavar :: Metavar -> Scheme fSource

Constructs a metavariable.

pf :: f (Scheme f) -> Scheme fSource

Constructs a pattern functor value.

toScheme :: (Regular a, Functor (PF a)) => a -> SchemeOf aSource

Recursively converts a value to a SchemeOf value.

data SchemeView f Source

A view on schemes to easily distinguish metavariables from pattern functor values.

Constructors

Metavar Metavar 
PF (f (Scheme f)) 

schemeView :: Scheme f -> SchemeView fSource

Returns the value corresponding to the SchemeView.

foldScheme :: Functor f => (Metavar -> a) -> (f a -> a) -> Scheme f -> aSource

Folds a Scheme value given a function to apply to metavariables and a function to apply to a pattern functor value.

Builder for transforming a rule specification to a rule.

class Regular (Target a) => Builder a whereSource

The type class Builder captures the functions, that are defined by induction on the type argument, that construct appropriate left and right values. These values are used to transform a rule specification to a rule.

Associated Types

type Target a :: *Source

Methods

base :: a -> RuleSpec (Target a)Source

diag :: a -> [RuleSpec (Target a)]Source

Instances

Regular a => Builder (RuleSpec a) 
(~ * b (Target a), Builder a, Regular b, LR (PF b)) => Builder (b -> a) 

ruleM :: (Builder r, Crush (PF (Target r)), Zip (PF (Target r)), Functor (PF (Target r))) => r -> Maybe (Rule (Target r))Source

Transforms a rule specification to a rule and returns Nothing if an unbound metavariable occurs in the right-hand side of the rule.

rule :: (Builder r, Crush (PF (Target r)), Functor (PF (Target r)), Zip (PF (Target r))) => r -> Rule (Target r)Source

Transforms a rule specification to a rule and throws a runtime error if an unbound metavariable occurs in the right-hand side of the rule.