| Copyright | (c) 2014 Patrick Bahr Emil Axelsson |
|---|---|
| License | BSD3 |
| Maintainer | Patrick Bahr <paba@di.ku.dk> |
| Stability | experimental |
| Portability | non-portable (GHC Extensions) |
| Safe Haskell | None |
| Language | Haskell98 |
Data.Comp.PAG
Description
This module implements recursion schemes derived from attribute grammars. The variant implemented in this module, called parametric attribute grammars, generalises both attribute grammars and attribute grammars with rewrite function (as implemented in Data.Comp.AG).
Synopsis
- runPAG :: forall f u d g. (Traversable f, Functor g, Functor d, Functor u) => Syn' f (u :*: d) u g -> Inh' f (u :*: d) d g -> (forall a. u a -> d (Context g a)) -> Term f -> u (Term g)
- class (Functor t, Foldable t) => Traversable (t :: * -> *)
- pr :: p :< q => q a -> p a
- type (:<) (f :: * -> *) (g :: * -> *) = Proj (ComprEmb (Elem f g)) f g
- fsnd :: (f :*: g) a -> g a
- ffst :: (f :*: g) a -> f a
- data ((f :: k -> *) :*: (g :: k -> *)) (a :: k) :: forall k. (k -> *) -> (k -> *) -> k -> * = (f a) :*: (g a)
- lookupNumMap' :: Int -> NumMap t a -> Maybe a
- lookupNumMap :: a -> Int -> NumMap t a -> a
- prodMap :: Mapping m k => v1 -> v2 -> m v1 -> m v2 -> m (v1, v2)
- number :: Traversable f => f a -> f (Numbered a)
- unNumbered :: Numbered a -> a
- data Numbered a = Numbered Int a
- class Functor m => Mapping (m :: * -> *) k | m -> k where
- data NumMap k v
- type Inh f p q g = q :< p => Inh' f p q g
- type Inh' f p q g = forall m i a. (Mapping m i, ?below :: i -> p a, ?above :: p a) => f i -> m (q (Context g a))
- type Syn f p q g = q :< p => Syn' f p q g
- type Syn' f p q g = forall child a. (?below :: child -> p a, ?above :: p a) => f child -> q (Context g a)
- below :: (?below :: child -> q a, p :< q) => child -> p a
- above :: (?above :: q a, p :< q) => p a
- prodSyn :: (p :< c, q :< c) => Syn f c p g -> Syn f c q g -> Syn f c (p :*: q) g
- (|*|) :: (p :< c, q :< c) => Syn f c p g -> Syn f c q g -> Syn f c (p :*: q) g
- prodInh :: (p :< c, q :< c, Functor p, Functor q) => Inh f c p g -> Inh f c q g -> Inh f c (p :*: q) g
- (>*<) :: (p :< c, q :< c, Functor p, Functor q) => Inh f c p g -> Inh f c q g -> Inh f c (p :*: q) g
Documentation
Arguments
| :: (Traversable f, Functor g, Functor d, Functor u) | |
| => Syn' f (u :*: d) u g | semantic function of synthesised attributes |
| -> Inh' f (u :*: d) d g | semantic function of inherited attributes |
| -> (forall a. u a -> d (Context g a)) | initialisation of inherited attributes |
| -> Term f | input term |
| -> u (Term g) |
This function runs a parametric attribute grammar on a term. The result is the (combined) synthesised attribute at the root of the term.
class (Functor t, Foldable t) => Traversable (t :: * -> *) #
Functors representing data structures that can be traversed from left to right.
A definition of traverse must satisfy the following laws:
- naturality
t .for every applicative transformationtraversef =traverse(t . f)t- identity
traverseIdentity = Identity- composition
traverse(Compose .fmapg . f) = Compose .fmap(traverseg) .traversef
A definition of sequenceA must satisfy the following laws:
- naturality
t .for every applicative transformationsequenceA=sequenceA.fmaptt- identity
sequenceA.fmapIdentity = Identity- composition
sequenceA.fmapCompose = Compose .fmapsequenceA.sequenceA
where an applicative transformation is a function
t :: (Applicative f, Applicative g) => f a -> g a
preserving the Applicative operations, i.e.
and the identity functor Identity and composition of functors Compose
are defined as
newtype Identity a = Identity a
instance Functor Identity where
fmap f (Identity x) = Identity (f x)
instance Applicative Identity where
pure x = Identity x
Identity f <*> Identity x = Identity (f x)
newtype Compose f g a = Compose (f (g a))
instance (Functor f, Functor g) => Functor (Compose f g) where
fmap f (Compose x) = Compose (fmap (fmap f) x)
instance (Applicative f, Applicative g) => Applicative (Compose f g) where
pure x = Compose (pure (pure x))
Compose f <*> Compose x = Compose ((<*>) <$> f <*> x)(The naturality law is implied by parametricity.)
Instances are similar to Functor, e.g. given a data type
data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)
a suitable instance would be
instance Traversable Tree where traverse f Empty = pure Empty traverse f (Leaf x) = Leaf <$> f x traverse f (Node l k r) = Node <$> traverse f l <*> f k <*> traverse f r
This is suitable even for abstract types, as the laws for <*>
imply a form of associativity.
The superclass instances should satisfy the following:
- In the
Functorinstance,fmapshould be equivalent to traversal with the identity applicative functor (fmapDefault). - In the
Foldableinstance,foldMapshould be equivalent to traversal with a constant applicative functor (foldMapDefault).
Instances
This function projects the component of type e out or the
compound value of type p.
type (:<) (f :: * -> *) (g :: * -> *) = Proj (ComprEmb (Elem f g)) f g infixl 5 #
The constraint e :< p expresses that e is a component of the
type p. That is, p is formed by binary products using the type
e. The occurrence of e must be unique. For example we have Int
:< (Bool,(Int,Bool)) but not Bool :< (Bool,(Int,Bool)).
data ((f :: k -> *) :*: (g :: k -> *)) (a :: k) :: forall k. (k -> *) -> (k -> *) -> k -> * infixr 8 #
Formal product of signatures (functors).
Constructors
| (f a) :*: (g a) infixr 8 |
Instances
| Proj (Found p) f g => Proj (Found (Ri p)) f (g' :*: g) | |
Defined in Data.Comp.Multi.Projection | |
| Proj (Found p) f g => Proj (Found (Le p)) f (g :*: g') | |
Defined in Data.Comp.Multi.Projection | |
| (Proj (Found p1) f1 g, Proj (Found p2) f2 g) => Proj (Found (Sum p1 p2)) (f1 :*: f2) g | |
Defined in Data.Comp.Multi.Projection | |
| (Functor f, Functor g) => Functor (f :*: g) | |
| (Foldable f, Foldable g) => Foldable (f :*: g) | |
Defined in Data.Comp.Ops Methods fold :: Monoid m => (f :*: g) m -> m # foldMap :: Monoid m => (a -> m) -> (f :*: g) a -> m # foldr :: (a -> b -> b) -> b -> (f :*: g) a -> b # foldr' :: (a -> b -> b) -> b -> (f :*: g) a -> b # foldl :: (b -> a -> b) -> b -> (f :*: g) a -> b # foldl' :: (b -> a -> b) -> b -> (f :*: g) a -> b # foldr1 :: (a -> a -> a) -> (f :*: g) a -> a # foldl1 :: (a -> a -> a) -> (f :*: g) a -> a # toList :: (f :*: g) a -> [a] # length :: (f :*: g) a -> Int # elem :: Eq a => a -> (f :*: g) a -> Bool # maximum :: Ord a => (f :*: g) a -> a # minimum :: Ord a => (f :*: g) a -> a # | |
| (Traversable f, Traversable g) => Traversable (f :*: g) | |
Defined in Data.Comp.Ops | |
lookupNumMap' :: Int -> NumMap t a -> Maybe a #
lookupNumMap :: a -> Int -> NumMap t a -> a #
prodMap :: Mapping m k => v1 -> v2 -> m v1 -> m v2 -> m (v1, v2) #
This function constructs the pointwise product of two maps each with a default value.
number :: Traversable f => f a -> f (Numbered a) #
This function numbers the components of the given functorial value with consecutive integers starting at 0.
unNumbered :: Numbered a -> a #
This type is used for numbering components of a functorial value.
class Functor m => Mapping (m :: * -> *) k | m -> k where #
Minimal complete definition
Methods
(&) :: m v -> m v -> m v infixr 0 #
left-biased union of two mappings.
(|->) :: k -> v -> m v infix 1 #
This operator constructs a singleton mapping.
This is the empty mapping.
prodMapWith :: (v1 -> v2 -> v) -> v1 -> v2 -> m v1 -> m v2 -> m v #
This function constructs the pointwise product of two maps each with a default value.
findWithDefault :: a -> k -> m a -> a #
Returns the value at the given key or returns the given default when the key is not an element of the map.
Instances
| Functor (NumMap k) | |
| Foldable (NumMap k) | |
Defined in Data.Comp.Mapping Methods fold :: Monoid m => NumMap k m -> m # foldMap :: Monoid m => (a -> m) -> NumMap k a -> m # foldr :: (a -> b -> b) -> b -> NumMap k a -> b # foldr' :: (a -> b -> b) -> b -> NumMap k a -> b # foldl :: (b -> a -> b) -> b -> NumMap k a -> b # foldl' :: (b -> a -> b) -> b -> NumMap k a -> b # foldr1 :: (a -> a -> a) -> NumMap k a -> a # foldl1 :: (a -> a -> a) -> NumMap k a -> a # elem :: Eq a => a -> NumMap k a -> Bool # maximum :: Ord a => NumMap k a -> a # minimum :: Ord a => NumMap k a -> a # | |
| Traversable (NumMap k) | |
| Mapping (NumMap k) (Numbered k) | |
type Inh f p q g = q :< p => Inh' f p q g Source #
The type of semantic functions for inherited attributes.
type Inh' f p q g = forall m i a. (Mapping m i, ?below :: i -> p a, ?above :: p a) => f i -> m (q (Context g a)) Source #
The type of semantic functions for inherited attributes. For
defining semantic functions use the type Inh, which includes the
inherited attribute that is defined by the semantic function into
the available attributes.
type Syn f p q g = q :< p => Syn' f p q g Source #
The type of semantic functions for synthesised attributes.
type Syn' f p q g = forall child a. (?below :: child -> p a, ?above :: p a) => f child -> q (Context g a) Source #
The type of semantic functions for synthesised attributes. For
defining semantic functions use the type Syn, which includes the
synthesised attribute that is defined by the semantic function into
the available attributes.
below :: (?below :: child -> q a, p :< q) => child -> p a Source #
This function provides access to attributes of the immediate children of the current node.
above :: (?above :: q a, p :< q) => p a Source #
This function provides access to attributes of the current node
prodSyn :: (p :< c, q :< c) => Syn f c p g -> Syn f c q g -> Syn f c (p :*: q) g Source #
Combines the semantic functions for two synthesised attributes to form a semantic function for the compound attribute consisting of the two original attributes.
(|*|) :: (p :< c, q :< c) => Syn f c p g -> Syn f c q g -> Syn f c (p :*: q) g Source #
Combines the semantic functions for two synthesised attributes to form a semantic function for the compound attribute consisting of the two original attributes.