Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | generics@haskell.org |
This is the top module for the rewriting library. All functionality is implemented in this module. For examples of how to use the library, see the included files in the directory examples, or the benchmark in the directory performance.
- class (Representable a, Typeable a, Eq a, Empty (Rep a), Extensible (Rep a), Matchable (Rep a), Substitutable (Rep a), Sampleable (Rep a), Diffable (Rep a), Validatable (Rep a)) => Rewritable a
- rewrite :: Rewritable a => Rule a -> a -> a
- rewriteM :: (Rewritable a, Monad m) => Rule a -> a -> m a
- validate :: Rewritable a => Rule a -> Bool
- synthesise :: (IsRule a, Nillable (Env a), Recordable (Env a), Testable (Env a), FiniteEnv (Env a) ~ True) => a -> Rule (Obj a)
- data Template a = Template a a Bool
- (+->) :: a -> a -> Template a
- (//) :: Template a -> Bool -> Template a
- data Rule a
- class Extensible a where
- class Matchable a where
- class Substitutable a where
- class Sampleable a where
- class Empty a where
- empty' :: a
- class HasRec a where
- type family Finite a :: *
- data True
- data False
- class Diffable a where
- class Validatable a where
- class Nillable gam where
- empty :: Subst gam
- class Typeable a
The class to signal availability of rewriting for a type
class (Representable a, Typeable a, Eq a, Empty (Rep a), Extensible (Rep a), Matchable (Rep a), Substitutable (Rep a), Sampleable (Rep a), Diffable (Rep a), Validatable (Rep a)) => Rewritable a Source
The Rewritable
class is used to signal types that can be rewritten and
to ``tie the recursive knot'' of the generic functions.
Top-level functions
rewrite :: Rewritable a => Rule a -> a -> aSource
Rewrite a term. The term is unchanged if the rule cannot be applied.
rewriteM :: (Rewritable a, Monad m) => Rule a -> a -> m aSource
Rewrite a term. Monad fail
is used if the rule cannot be applied.
validate :: Rewritable a => Rule a -> BoolSource
Validate a rewrite rule
synthesise :: (IsRule a, Nillable (Env a), Recordable (Env a), Testable (Env a), FiniteEnv (Env a) ~ True) => a -> Rule (Obj a)Source
Synthesise a function into a rewrite rule
Building rewrite rules
Internal classes: might be necessary to add new base types
class Extensible a whereSource
Schemes
Extensible Char | |
Extensible Float | |
Extensible Int | |
Extensible U | |
Rewritable a => Extensible (Var a) | |
Rewritable a => Extensible (Rec a) | |
(Extensible a, Extensible b) => Extensible (:+: a b) | |
(Extensible a, Extensible b) => Extensible (:*: a b) | |
Extensible a => Extensible (C c a) |
Matching
class Substitutable a whereSource
Substituting
Substitutable Char | |
Substitutable Float | |
Substitutable Int | |
Substitutable U | |
Rewritable a => Substitutable (Var a) | |
Rewritable a => Substitutable (Rec a) | |
(Substitutable a, Substitutable b) => Substitutable (:+: a b) | |
(Substitutable a, Substitutable b) => Substitutable (:*: a b) | |
Substitutable a => Substitutable (C c a) |
class Sampleable a whereSource
Sampling
Sampleable Float | |
Bounded a => Sampleable a | |
Sampleable U | |
Rewritable a => Sampleable (Var a) | |
Rewritable a => Sampleable (Rec a) | |
(Representable a, Empty (Rep a), Representable b, Empty (Rep b)) => Sampleable (:+: a b) | |
(Sampleable a, Sampleable b) => Sampleable (:*: a b) | |
Sampleable a => Sampleable (C c a) |
Type level validation for the datatypes to be rewritten: there can be no recursive calls on the leftmost constructor
Diff
class Validatable a whereSource
Validating synthesised rules
Validatable Char | |
Validatable Float | |
Validatable Int | |
Validatable U | |
Rewritable a => Validatable (Var a) | |
Rewritable a => Validatable (Rec a) | |
(Validatable a, Validatable b) => Validatable (:+: a b) | |
(Validatable a, Validatable b) => Validatable (:*: a b) | |
Validatable a => Validatable (C c a) |
Re-exported for convenience
class Typeable a
The class Typeable
allows a concrete representation of a type to
be calculated.
Typeable Bool | |
Typeable Char | |
Typeable Double | |
Typeable Float | |
Typeable Int | |
Typeable Int8 | |
Typeable Int16 | |
Typeable Int32 | |
Typeable Int64 | |
Typeable Integer | |
Typeable Ordering | |
Typeable RealWorld | |
Typeable Word | |
Typeable Word8 | |
Typeable Word16 | |
Typeable Word32 | |
Typeable Word64 | |
Typeable () | |
Typeable TypeRep | |
Typeable TyCon | |
(Typeable1 s, Typeable a) => Typeable (s a) | One Typeable instance for all Typeable1 instances |