deep-transformations-0.4.0.1: Deep natural and unnatural tree transformations, including attribute grammars
Safe HaskellNone
LanguageHaskell2010

Transformation.AG.Generics

Description

This module can be used to scrap the boilerplate attribute declarations. In particular:

  • If an attribution rule 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 an Auto constructor and deriving the Generic instance 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 Folded constructor 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 Mapped constructor and calculated automatically.
  • If the attribute additionally carries an applicative effect, the Mapped wrapper can be replaced by Traversed.
Synopsis

Type wrappers for automatic attribute inference

newtype Auto t Source #

Transformation wrapper that allows automatic inference of attribute rules.

Constructors

Auto t 

Instances

Instances details
Attribution t => Attribution (Auto t) Source # 
Instance details

Defined in Transformation.AG.Generics

Associated Types

type Origin (Auto t) 
Instance details

Defined in Transformation.AG.Generics

type Origin (Auto t) = Origin t

Methods

unwrap :: Auto t -> Origin (Auto t) x -> x Source #

(Attribution t, Bequether (Auto t) g, Synthesizer (Auto t) g) => At (Auto t) g Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

attribution :: forall (sem :: Type -> Type). Traversable (g sem) => Auto t -> Origin (Auto t) (g sem sem) -> (Inherited (Auto t) (g sem sem), g sem (Synthesized (Auto t))) -> (Synthesized (Auto t) (g sem sem), g sem (Inherited (Auto t))) Source #

(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 # 
Instance details

Defined in Transformation.AG.Generics

Methods

bequest :: forall (sem :: Type -> Type). Auto t -> Origin (Auto t) (g sem sem) -> Atts (Inherited (Auto t)) g -> g sem (Synthesized (Auto t)) -> g sem (Inherited (Auto t)) Source #

(Attribution t, Atts (Synthesized (Auto t)) g ~ result, Generic result, GenericSynthesizer (Auto t) g (Rep result)) => Synthesizer (Auto t) g Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

synthesis :: forall (sem :: Type -> Type). Auto t -> Origin (Auto t) (g sem sem) -> Atts (Inherited (Auto t)) g -> g sem (Synthesized (Auto t)) -> Atts (Synthesized (Auto t)) g Source #

type Origin (Auto t) Source # 
Instance details

Defined in Transformation.AG.Generics

type Origin (Auto t) = Origin t
type Atts (Inherited (Auto t)) x Source # 
Instance details

Defined in Transformation.AG.Generics

type Atts (Inherited (Auto t)) x = Atts (Inherited t) x
type Atts (Synthesized (Auto t)) x Source # 
Instance details

Defined in Transformation.AG.Generics

type Atts (Synthesized (Auto t)) x = Atts (Synthesized t) x

newtype Folded a Source #

Wrapper for a field that should be automatically synthesized by folding together all child nodes' synthesized attributes of the same name.

Constructors

Folded 

Fields

Instances

Instances details
(Attribution t, Monoid a, forall (sem :: Type -> Type). Foldable (Accumulator t name a) (g sem)) => SynthesizedField name (Folded a) t g Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

synthesizedField :: forall (sem :: Type -> Type). Proxy name -> t -> Origin t (g sem sem) -> Atts (Inherited t) g -> g sem (Synthesized t) -> Folded a Source #

Monoid a => Monoid (Folded a) Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

mempty :: Folded a #

mappend :: Folded a -> Folded a -> Folded a #

mconcat :: [Folded a] -> Folded a #

Semigroup a => Semigroup (Folded a) Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

(<>) :: Folded a -> Folded a -> Folded a #

sconcat :: NonEmpty (Folded a) -> Folded a #

stimes :: Integral b => b -> Folded a -> Folded a #

Show a => Show (Folded a) Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

showsPrec :: Int -> Folded a -> ShowS #

show :: Folded a -> String #

showList :: [Folded a] -> ShowS #

Eq a => Eq (Folded a) Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

(==) :: Folded a -> Folded a -> Bool #

(/=) :: Folded a -> Folded a -> Bool #

Ord a => Ord (Folded a) Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

compare :: Folded a -> Folded a -> Ordering #

(<) :: Folded a -> Folded a -> Bool #

(<=) :: Folded a -> Folded a -> Bool #

(>) :: Folded a -> Folded a -> Bool #

(>=) :: Folded a -> Folded a -> Bool #

max :: Folded a -> Folded a -> Folded a #

min :: Folded a -> Folded a -> Folded a #

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.

Constructors

Mapped 

Fields

Instances

Instances details
(Attribution t, Origin t ~ f, Functor f, Functor (Replicator t f name) (g f)) => SynthesizedField name (Mapped f (g f f)) t g Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

synthesizedField :: forall (sem :: Type -> Type). Proxy name -> t -> Origin t (g sem sem) -> Atts (Inherited t) g -> g sem (Synthesized t) -> Mapped f (g f f) Source #

Foldable f => Foldable (Mapped f) Source # 
Instance details

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 #

toList :: Mapped f a -> [a] #

null :: Mapped f a -> Bool #

length :: Mapped f a -> Int #

elem :: Eq a => a -> Mapped f a -> Bool #

maximum :: Ord a => Mapped f a -> a #

minimum :: Ord a => Mapped f a -> a #

sum :: Num a => Mapped f a -> a #

product :: Num a => Mapped f a -> a #

Applicative f => Applicative (Mapped f) Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

pure :: a -> Mapped f a #

(<*>) :: Mapped f (a -> b) -> Mapped f a -> Mapped f b #

liftA2 :: (a -> b -> c) -> Mapped f a -> Mapped f b -> Mapped f c #

(*>) :: Mapped f a -> Mapped f b -> Mapped f b #

(<*) :: Mapped f a -> Mapped f b -> Mapped f a #

Functor f => Functor (Mapped f) Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

fmap :: (a -> b) -> Mapped f a -> Mapped f b #

(<$) :: a -> Mapped f b -> Mapped f a #

Monad f => Monad (Mapped f) Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

(>>=) :: Mapped f a -> (a -> Mapped f b) -> Mapped f b #

(>>) :: Mapped f a -> Mapped f b -> Mapped f b #

return :: a -> Mapped f a #

Monoid (f a) => Monoid (Mapped f a) Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

mempty :: Mapped f a #

mappend :: Mapped f a -> Mapped f a -> Mapped f a #

mconcat :: [Mapped f a] -> Mapped f a #

Semigroup (f a) => Semigroup (Mapped f a) Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

(<>) :: Mapped f a -> Mapped f a -> Mapped f a #

sconcat :: NonEmpty (Mapped f a) -> Mapped f a #

stimes :: Integral b => b -> Mapped f a -> Mapped f a #

Show (f a) => Show (Mapped f a) Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

showsPrec :: Int -> Mapped f a -> ShowS #

show :: Mapped f a -> String #

showList :: [Mapped f a] -> ShowS #

Eq (f a) => Eq (Mapped f a) Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

(==) :: Mapped f a -> Mapped f a -> Bool #

(/=) :: Mapped f a -> Mapped f a -> Bool #

Ord (f a) => Ord (Mapped f a) Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

compare :: Mapped f a -> Mapped f a -> Ordering #

(<) :: Mapped f a -> Mapped f a -> Bool #

(<=) :: Mapped f a -> Mapped f a -> Bool #

(>) :: Mapped f a -> Mapped f a -> Bool #

(>=) :: Mapped f a -> Mapped f a -> Bool #

max :: Mapped f a -> Mapped f a -> Mapped f a #

min :: Mapped f a -> Mapped f a -> Mapped f a #

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

Instances details
(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 # 
Instance details

Defined in Transformation.AG.Generics

Methods

synthesizedField :: forall (sem :: Type -> Type). Proxy name -> t -> Origin t (g sem sem) -> Atts (Inherited t) g -> g sem (Synthesized t) -> Traversed m f g Source #

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

bequest Source #

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

-> g sem (Inherited t) 

Instances

Instances details
(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 # 
Instance details

Defined in Transformation.AG.Generics

Methods

bequest :: forall (sem :: Type -> Type). Auto t -> Origin (Auto t) (g sem sem) -> Atts (Inherited (Auto t)) g -> g sem (Synthesized (Auto t)) -> g sem (Inherited (Auto t)) Source #

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

synthesis Source #

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

Instances details
(Attribution t, Atts (Synthesized (Auto t)) g ~ result, Generic result, GenericSynthesizer (Auto t) g (Rep result)) => Synthesizer (Auto t) g Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

synthesis :: forall (sem :: Type -> Type). Auto t -> Origin (Auto t) (g sem sem) -> Atts (Inherited (Auto t)) g -> g sem (Synthesized (Auto t)) -> Atts (Synthesized (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

synthesizedField Source #

Arguments

:: forall (sem :: Type -> Type). Proxy name

attribute name

-> t

transformation

-> Origin t (g sem sem)

tree node

-> Atts (Inherited t) g

inherited attributes

-> g sem (Synthesized t)

synthesized attributes

-> result 

Instances

Instances details
(Attribution t, Monoid a, forall (sem :: Type -> Type). Foldable (Accumulator t name a) (g sem)) => SynthesizedField name (Folded a) t g Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

synthesizedField :: forall (sem :: Type -> Type). Proxy name -> t -> Origin t (g sem sem) -> Atts (Inherited t) g -> g sem (Synthesized t) -> Folded a Source #

(Attribution t, Origin t ~ f, Functor f, Functor (Replicator t f name) (g f)) => SynthesizedField name (Mapped f (g f f)) t g Source # 
Instance details

Defined in Transformation.AG.Generics

Methods

synthesizedField :: forall (sem :: Type -> Type). Proxy name -> t -> Origin t (g sem sem) -> Atts (Inherited t) g -> g sem (Synthesized t) -> Mapped f (g f f) Source #

(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 # 
Instance details

Defined in Transformation.AG.Generics

Methods

synthesizedField :: forall (sem :: Type -> Type). Proxy name -> t -> Origin t (g sem sem) -> Atts (Inherited t) g -> g sem (Synthesized t) -> Traversed m f g Source #

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.