| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Transformation.AG.Generics
Description
This module can be used to scrap the boilerplate attribute declarations. In particular:
- If an
attributionrule always merely copies the inherited attributes to the children's inherited attributes of the same name, the rule can be left out by wrapping the transformation into anAutoconstructor and deriving theGenericinstance of the inherited attributes. - A synthesized attribute whose value is a fold of all same-named attributes of the children can be wrapped in the
Foldedconstructor and calculated automatically. - A synthesized attribute that is a copy of the current node but with every child taken from the same-named
synthesized child attribute can be wrapped in the
Mappedconstructor and calculated automatically. - If the attribute additionally carries an applicative effect, the
Mappedwrapper can be replaced byTraversed.
Synopsis
- newtype Auto t = Auto t
- newtype Folded a = Folded {
- getFolded :: a
- newtype Mapped (f :: k -> Type) (a :: k) = Mapped {
- getMapped :: f a
- newtype Traversed (m :: k -> Type) (f :: k1 -> k) (g :: (k1 -> k) -> (k1 -> k) -> k1) = Traversed {
- getTraversed :: m (f (g f f))
- class Bequether t (g :: (Type -> Type) -> (Type -> Type) -> Type) where
- class Attribution t => Synthesizer t (g :: (Type -> Type) -> (Type -> Type) -> Type) where
- synthesis :: forall (sem :: Type -> Type). t -> Origin t (g sem sem) -> Atts (Inherited t) g -> g sem (Synthesized t) -> Atts (Synthesized t) g
- class Attribution t => SynthesizedField (name :: Symbol) result t (g :: (Type -> Type) -> (Type -> Type) -> Type) where
- synthesizedField :: forall (sem :: Type -> Type). Proxy name -> t -> Origin t (g sem sem) -> Atts (Inherited t) g -> g sem (Synthesized t) -> result
- foldedField :: forall {k} (name :: Symbol) t g a (sem :: k). (Monoid a, Foldable (Accumulator t name a) (g sem)) => Proxy name -> t -> g sem (Synthesized t) -> Folded a
- mappedField :: forall (name :: Symbol) t g (f :: Type -> Type) (sem :: Type -> Type). Functor (Replicator t f name) (g f) => Proxy name -> t -> g sem (Synthesized t) -> g f f
- passDown :: forall {k} t g (shallow :: Type -> Type) (deep :: k) atts. Functor (PassDown t shallow atts) (g deep) => atts -> g deep shallow -> g deep (Inherited t)
- bequestDefault :: forall t g (sem :: Type -> Type). (Attribution t, Functor (PassDown t sem (Atts (Inherited t) g)) (g sem)) => t -> Origin t (g sem sem) -> Atts (Inherited t) g -> g sem (Synthesized t) -> g sem (Inherited t)
Type wrappers for automatic attribute inference
Transformation wrapper that allows automatic inference of attribute rules.
Constructors
| Auto t |
Instances
| Attribution t => Attribution (Auto t) Source # | |
| (Attribution t, Bequether (Auto t) g, Synthesizer (Auto t) g) => At (Auto t) g Source # | |
Defined in Transformation.AG.Generics | |
| (Attribution t, a ~ Atts (Inherited (Auto t)) g, forall (deep :: Type -> Type). Functor (PassDown (Auto t) deep a) (g deep)) => Bequether (Auto t) g Source # | |
| (Attribution t, Atts (Synthesized (Auto t)) g ~ result, Generic result, GenericSynthesizer (Auto t) g (Rep result)) => Synthesizer (Auto t) g Source # | |
| type Origin (Auto t) Source # | |
Defined in Transformation.AG.Generics | |
| type Atts (Inherited (Auto t)) x Source # | |
| type Atts (Synthesized (Auto t)) x Source # | |
Defined in Transformation.AG.Generics | |
Wrapper for a field that should be automatically synthesized by folding together all child nodes' synthesized attributes of the same name.
Instances
| (Attribution t, Monoid a, forall (sem :: Type -> Type). Foldable (Accumulator t name a) (g sem)) => SynthesizedField name (Folded a) t g Source # | |
Defined in Transformation.AG.Generics | |
| Monoid a => Monoid (Folded a) Source # | |
| Semigroup a => Semigroup (Folded a) Source # | |
| Show a => Show (Folded a) Source # | |
| Eq a => Eq (Folded a) Source # | |
| Ord a => Ord (Folded a) Source # | |
Defined in Transformation.AG.Generics | |
newtype Mapped (f :: k -> Type) (a :: k) Source #
Wrapper for a field that should be automatically synthesized by replacing every child node by its synthesized attribute of the same name.
Instances
| (Attribution t, Origin t ~ f, Functor f, Functor (Replicator t f name) (g f)) => SynthesizedField name (Mapped f (g f f)) t g Source # | |
Defined in Transformation.AG.Generics | |
| Foldable f => Foldable (Mapped f) Source # | |
Defined in Transformation.AG.Generics Methods fold :: Monoid m => Mapped f m -> m # foldMap :: Monoid m => (a -> m) -> Mapped f a -> m # foldMap' :: Monoid m => (a -> m) -> Mapped f a -> m # foldr :: (a -> b -> b) -> b -> Mapped f a -> b # foldr' :: (a -> b -> b) -> b -> Mapped f a -> b # foldl :: (b -> a -> b) -> b -> Mapped f a -> b # foldl' :: (b -> a -> b) -> b -> Mapped f a -> b # foldr1 :: (a -> a -> a) -> Mapped f a -> a # foldl1 :: (a -> a -> a) -> Mapped f a -> a # elem :: Eq a => a -> Mapped f a -> Bool # maximum :: Ord a => Mapped f a -> a # minimum :: Ord a => Mapped f a -> a # | |
| Applicative f => Applicative (Mapped f) Source # | |
| Functor f => Functor (Mapped f) Source # | |
| Monad f => Monad (Mapped f) Source # | |
| Monoid (f a) => Monoid (Mapped f a) Source # | |
| Semigroup (f a) => Semigroup (Mapped f a) Source # | |
| Show (f a) => Show (Mapped f a) Source # | |
| Eq (f a) => Eq (Mapped f a) Source # | |
| Ord (f a) => Ord (Mapped f a) Source # | |
Defined in Transformation.AG.Generics | |
newtype Traversed (m :: k -> Type) (f :: k1 -> k) (g :: (k1 -> k) -> (k1 -> k) -> k1) Source #
Wrapper for a field that should be automatically synthesized by traversing over all child nodes and applying each node's synthesized attribute of the same name.
Constructors
| Traversed | |
Fields
| |
Instances
| (Attribution t, Origin t ~ f, Traversable f, Applicative m, Traversable (Traverser t m f name) (g f)) => SynthesizedField name (Traversed m f g) t g Source # | |
Defined in Transformation.AG.Generics | |
Type classes replacing Attribution
class Bequether t (g :: (Type -> Type) -> (Type -> Type) -> Type) where Source #
A half of the Attribution class used to specify all inherited attributes.
Methods
class Attribution t => Synthesizer t (g :: (Type -> Type) -> (Type -> Type) -> Type) where Source #
A half of the Attribution class used to specify all synthesized attributes.
Methods
Arguments
| :: forall (sem :: Type -> Type). t | transformation |
| -> Origin t (g sem sem) | tree node |
| -> Atts (Inherited t) g | inherited attributes |
| -> g sem (Synthesized t) | synthesized attributes |
| -> Atts (Synthesized t) g |
Instances
| (Attribution t, Atts (Synthesized (Auto t)) g ~ result, Generic result, GenericSynthesizer (Auto t) g (Rep result)) => Synthesizer (Auto t) g Source # | |
class Attribution t => SynthesizedField (name :: Symbol) result t (g :: (Type -> Type) -> (Type -> Type) -> Type) where Source #
Class for specifying a single named attribute
Methods
Instances
| (Attribution t, Monoid a, forall (sem :: Type -> Type). Foldable (Accumulator t name a) (g sem)) => SynthesizedField name (Folded a) t g Source # | |
Defined in Transformation.AG.Generics | |
| (Attribution t, Origin t ~ f, Functor f, Functor (Replicator t f name) (g f)) => SynthesizedField name (Mapped f (g f f)) t g Source # | |
Defined in Transformation.AG.Generics | |
| (Attribution t, Origin t ~ f, Traversable f, Applicative m, Traversable (Traverser t m f name) (g f)) => SynthesizedField name (Traversed m f g) t g Source # | |
Defined in Transformation.AG.Generics | |
The default behaviour on generic datatypes
foldedField :: forall {k} (name :: Symbol) t g a (sem :: k). (Monoid a, Foldable (Accumulator t name a) (g sem)) => Proxy name -> t -> g sem (Synthesized t) -> Folded a Source #
The default synthesizedField method definition for Folded fields.
mappedField :: forall (name :: Symbol) t g (f :: Type -> Type) (sem :: Type -> Type). Functor (Replicator t f name) (g f) => Proxy name -> t -> g sem (Synthesized t) -> g f f Source #
The default synthesizedField method definition for Mapped fields.
passDown :: forall {k} t g (shallow :: Type -> Type) (deep :: k) atts. Functor (PassDown t shallow atts) (g deep) => atts -> g deep shallow -> g deep (Inherited t) Source #
Pass down the given record of inherited fields to child nodes.
bequestDefault :: forall t g (sem :: Type -> Type). (Attribution t, Functor (PassDown t sem (Atts (Inherited t) g)) (g sem)) => t -> Origin t (g sem sem) -> Atts (Inherited t) g -> g sem (Synthesized t) -> g sem (Inherited t) Source #
The default bequest method definition relies on generics to automatically pass down all same-named inherited
attributes.