Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
A special case of an attribute grammar where every node has only a single inherited and a single synthesized
attribute of the same monoidal type. The synthesized attributes of child nodes are all mconcat
ted together.
Synopsis
- newtype Auto t = Auto t
- newtype Keep t = Keep t
- data Atts a b = Atts {}
- type Semantics a b = Const (a -> b)
- type PreservingSemantics f a b = Compose ((->) a) (Compose ((,) (Atts a b)) f)
- type Rule a b = Atts a b -> Atts a b
- knit :: (Foldable (g sem), sem ~ Semantics a b, Monoid a, Monoid b) => Rule a b -> g sem sem -> sem (g sem sem)
- knitKeeping :: forall a b f g sem. (Foldable (g sem), sem ~ PreservingSemantics f a b, Monoid a, Monoid b, Foldable f, Functor f) => Rule a b -> f (g sem sem) -> sem (g sem sem)
- class Attribution t a b g (deep :: Type -> Type) shallow where
- attribution :: t -> shallow (g deep deep) -> Rule a b
- applyDefault :: (p ~ Domain t, q ~ Semantics a b, x ~ g q q, Foldable (g q), Attribution t a b g q p, Monoid a, Monoid b) => (forall y. p y -> y) -> t -> p x -> q x
- fullMapDefault :: (p ~ Domain t, q ~ Semantics a b, q ~ Codomain t, x ~ g q q, Foldable (g q), Functor t g, Attribution t a b g p p, Monoid a, Monoid b) => (forall y. p y -> y) -> t -> p (g p p) -> q (g q q)
- applyDefaultWithAttributes :: (p ~ Domain t, q ~ PreservingSemantics p a b, x ~ g q q, Attribution t a b g q p, Foldable (g q), Monoid a, Monoid b, Foldable p, Functor p) => t -> p x -> q x
- traverseDefaultWithAttributes :: forall t p q r a b g. (Transformation t, Domain t ~ p, Codomain t ~ Compose ((->) a) q, q ~ Compose ((,) (Atts a b)) p, r ~ Compose ((->) a) q, Traversable p, Functor t g, Traversable (Feeder a b p) g, At t (g r r)) => t -> p (g p p) -> a -> q (g q q)
- data Feeder a b (f :: Type -> Type) = Feeder
Documentation
Transformation wrapper that allows automatic inference of attribute rules.
Auto t |
Instances
(Transformation (Auto t), Domain (Auto t) ~ f, Functor f, Codomain (Auto t) ~ Semantics a b, Functor (Auto t) g, At (Auto t) (g (Semantics a b) (Semantics a b))) => Functor (Auto t) g Source # | |
(Transformation (Auto t), p ~ Domain (Auto t), q ~ Codomain (Auto t), q ~ Semantics a b, Foldable (g q), Monoid a, Monoid b, Foldable p, Attribution (Auto t) a b g q p) => At (Auto t) (g (Semantics a b) (Semantics a b)) Source # | |
Transformation wrapper that allows automatic inference of attribute rules and preservation of the attribute with the original nodes.
Keep t |
Instances
Instances
(Transformation (Keep t), p ~ Domain (Keep t), q ~ Codomain (Keep t), q ~ PreservingSemantics p a b, Foldable (g q), Monoid a, Monoid b, Foldable p, Functor p, Attribution (Keep t) a b g q p) => At (Keep t) (g (PreservingSemantics p a b) (PreservingSemantics p a b)) Source # | |
Defined in Transformation.AG.Dimorphic ($) :: Keep t -> Domain (Keep t) (g (PreservingSemantics p a b) (PreservingSemantics p a b)) -> Codomain (Keep t) (g (PreservingSemantics p a b) (PreservingSemantics p a b)) Source # | |
(Transformation (Keep t), p ~ Domain (Keep t), q ~ Codomain (Keep t), q ~ PreservingSemantics p a, Foldable (g q), Monoid a, Foldable p, Functor p, Attribution (Keep t) a g q p) => At (Keep t) (g (PreservingSemantics p a) (PreservingSemantics p a)) Source # | |
Defined in Transformation.AG.Monomorphic ($) :: Keep t -> Domain (Keep t) (g (PreservingSemantics p a) (PreservingSemantics p a)) -> Codomain (Keep t) (g (PreservingSemantics p a) (PreservingSemantics p a)) Source # | |
(Data a, Data b) => Data (Atts a b) Source # | |
Defined in Transformation.AG.Dimorphic gfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> Atts a b -> c (Atts a b) # gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Atts a b) # toConstr :: Atts a b -> Constr # dataTypeOf :: Atts a b -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Atts a b)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Atts a b)) # gmapT :: (forall b0. Data b0 => b0 -> b0) -> Atts a b -> Atts a b # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Atts a b -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Atts a b -> r # gmapQ :: (forall d. Data d => d -> u) -> Atts a b -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Atts a b -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Atts a b -> m (Atts a b) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Atts a b -> m (Atts a b) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Atts a b -> m (Atts a b) # | |
(Monoid a, Monoid b) => Monoid (Atts a b) Source # | |
(Semigroup a, Semigroup b) => Semigroup (Atts a b) Source # | |
(Show a, Show b) => Show (Atts a b) Source # | |
type Semantics a b = Const (a -> b) Source #
A node's Semantics
maps its inherited attribute to its synthesized attribute.
type PreservingSemantics f a b = Compose ((->) a) (Compose ((,) (Atts a b)) f) Source #
A node's PreservingSemantics
maps its inherited attribute to its synthesized attribute.
type Rule a b = Atts a b -> Atts a b Source #
An attribution rule maps a node's inherited attribute and its child nodes' synthesized attribute to the node's synthesized attribute and the children nodes' inherited attributes.
knit :: (Foldable (g sem), sem ~ Semantics a b, Monoid a, Monoid b) => Rule a b -> g sem sem -> sem (g sem sem) Source #
knitKeeping :: forall a b f g sem. (Foldable (g sem), sem ~ PreservingSemantics f a b, Monoid a, Monoid b, Foldable f, Functor f) => Rule a b -> f (g sem sem) -> sem (g sem sem) Source #
Another way to tie the recursive knot, using a Rule
to add attributes to every node througha stateful calculation
class Attribution t a b g (deep :: Type -> Type) shallow where Source #
The core type class for defining the attribute grammar. The instances of this class typically have a form like
instance Attribution MyAttGrammar MyMonoid MyNode (Semantics MyAttGrammar) Identity where attribution MyAttGrammar{} (Identity MyNode{}) Atts{inh= fromParent, syn= fromChildren} = Atts{syn= toParent, inh= toChildren}
attribution :: t -> shallow (g deep deep) -> Rule a b Source #
The attribution rule for a given transformation and node.
Instances
Attribution t a b g deep shallow Source # | |
Defined in Transformation.AG.Dimorphic attribution :: t -> shallow (g deep deep) -> Rule a b Source # |
applyDefault :: (p ~ Domain t, q ~ Semantics a b, x ~ g q q, Foldable (g q), Attribution t a b g q p, Monoid a, Monoid b) => (forall y. p y -> y) -> t -> p x -> q x Source #
Drop-in implementation of $
fullMapDefault :: (p ~ Domain t, q ~ Semantics a b, q ~ Codomain t, x ~ g q q, Foldable (g q), Functor t g, Attribution t a b g p p, Monoid a, Monoid b) => (forall y. p y -> y) -> t -> p (g p p) -> q (g q q) Source #
Drop-in implementation of <$>
applyDefaultWithAttributes :: (p ~ Domain t, q ~ PreservingSemantics p a b, x ~ g q q, Attribution t a b g q p, Foldable (g q), Monoid a, Monoid b, Foldable p, Functor p) => t -> p x -> q x Source #
Drop-in implementation of $
that stores all attributes with every original node
traverseDefaultWithAttributes :: forall t p q r a b g. (Transformation t, Domain t ~ p, Codomain t ~ Compose ((->) a) q, q ~ Compose ((,) (Atts a b)) p, r ~ Compose ((->) a) q, Traversable p, Functor t g, Traversable (Feeder a b p) g, At t (g r r)) => t -> p (g p p) -> a -> q (g q q) Source #
Drop-in implementation of traverse
that stores all attributes with every original node