fixplate-0.1.5: Uniplate-style generic traversals for optionally annotated fixed-point types.Source codeContentsIndex
Data.Generics.Fixplate.Base
Contents
Annotations
Co-annotations
Annotated trees
Holes
Higher-order type classes
Attrib (cofree comonad)
CoAttrib (free monad)
Description
The core types of Fixplate.
Synopsis
newtype Mu f = Fix {
unFix :: f (Mu f)
}
isAtom :: Foldable f => Mu f -> Bool
data Ann f a b = Ann {
attr :: a
unAnn :: f b
}
type Attr f a = Mu (Ann f a)
liftAnn :: (f e -> g e) -> Ann f a e -> Ann g a e
data CoAnn f a b
= Pure a
| CoAnn (f b)
type CoAttr f a = Mu (CoAnn f a)
liftCoAnn :: (f e -> g e) -> CoAnn f a e -> CoAnn g a e
attribute :: Attr f a -> a
forget :: Functor f => Attr f a -> Mu f
data Hole = Hole
class EqF f where
equalF :: Eq a => f a -> f a -> Bool
class EqF f => OrdF f where
compareF :: Ord a => f a -> f a -> Ordering
class ShowF f where
showsPrecF :: Show a => Int -> f a -> ShowS
class ReadF f where
readPrecF :: Read a => ReadPrec (f a)
showF :: (ShowF f, Show a) => f a -> String
showsF :: (ShowF f, Show a) => f a -> ShowS
newtype Attrib f a = Attrib {
unAttrib :: Attr f a
}
newtype CoAttrib f a = CoAttrib {
unCoAttrib :: CoAttr f a
}
Documentation
newtype Mu f Source
The fixed-point type.
Constructors
Fix
unFix :: f (Mu f)
show/hide Instances
EqF f => Eq (Mu f)
OrdF f => Ord (Mu f)
ReadF f => Read (Mu f)
ShowF f => Show (Mu f)
isAtom :: Foldable f => Mu f -> BoolSource
We call a tree "atomic" if it has no subtrees.
Annotations
data Ann f a b Source
Type of annotations
Constructors
Ann
attr :: athe annotation
unAnn :: f bthe original functor
show/hide Instances
Functor f => Functor (Ann f a)
Foldable f => Foldable (Ann f a)
Traversable f => Traversable (Ann f a)
(Read a, ReadF f) => ReadF (Ann f a)
(Show a, ShowF f) => ShowF (Ann f a)
(Ord a, OrdF f) => OrdF (Ann f a)
(Eq a, EqF f) => EqF (Ann f a)
(Eq a, Eq (f b)) => Eq (Ann f a b)
(Ord a, Ord (f b)) => Ord (Ann f a b)
(Show a, Show (f b)) => Show (Ann f a b)
type Attr f a = Mu (Ann f a)Source
Annotated fixed-point type. Equivalent to CoFree f a
liftAnn :: (f e -> g e) -> Ann f a e -> Ann g a eSource
Lifting natural transformations to annotations.
Co-annotations
data CoAnn f a b Source
Categorical dual of Ann.
Constructors
Pure a
CoAnn (f b)
show/hide Instances
Functor f => Functor (CoAnn f a)
Foldable f => Foldable (CoAnn f a)
Traversable f => Traversable (CoAnn f a)
(Show a, ShowF f) => ShowF (CoAnn f a)
(Ord a, OrdF f) => OrdF (CoAnn f a)
(Eq a, EqF f) => EqF (CoAnn f a)
(Eq a, Eq (f b)) => Eq (CoAnn f a b)
(Ord a, Ord (f b)) => Ord (CoAnn f a b)
(Show a, Show (f b)) => Show (CoAnn f a b)
type CoAttr f a = Mu (CoAnn f a)Source
Categorical dual of Attr. Equivalent to Free f a
liftCoAnn :: (f e -> g e) -> CoAnn f a e -> CoAnn g a eSource
Lifting natural transformations to annotations.
Annotated trees
attribute :: Attr f a -> aSource
The attribute of the root node.
forget :: Functor f => Attr f a -> Mu fSource
A function forgetting all the attributes from an annotated tree.
Holes
data Hole Source

This a data type defined to be a place-holder for childs. It is used in tree drawing, hashing, and Shape.

It is deliberately not made an instance of Show, so that you can choose your preferred style. For example, an acceptable choice is

 instance Show Hole where show _ = "_"
Constructors
Hole
show/hide Instances
Higher-order type classes
class EqF f whereSource

"Functorised" versions of standard type classes. If you have your a structure functor, for example

 Expr e 
   = Kst Int 
   | Var String 
   | Add e e 
   deriving (Eq,Ord,Read,Show,Functor,Foldable,Traversable)

you should make it an instance of these, so that the fixed-point type Mu Expr can be an instance of Eq, Ord and Show. Doing so is very easy:

 instance EqF   Expr where equalF     = (==)
 instance OrdF  Expr where compareF   = compare
 instance ShowF Expr where showsPrecF = showsPrec

The Read instance depends on whether we are using GHC or not. The Haskell98 version is

 instance ReadF Expr where readsPrecF = readsPrec

while the GHC version is

 instance ReadF Expr where readPrecF  = readPrec
Methods
equalF :: Eq a => f a -> f a -> BoolSource
show/hide Instances
(Eq a, EqF f) => EqF (CoAnn f a)
(Eq a, EqF f) => EqF (Ann f a)
(Eq hash, EqF f) => EqF (HashAnn hash f)
class EqF f => OrdF f whereSource
Methods
compareF :: Ord a => f a -> f a -> OrderingSource
show/hide Instances
(Ord a, OrdF f) => OrdF (CoAnn f a)
(Ord a, OrdF f) => OrdF (Ann f a)
(Ord hash, OrdF f) => OrdF (HashAnn hash f)
class ShowF f whereSource
Methods
showsPrecF :: Show a => Int -> f a -> ShowSSource
show/hide Instances
(Show a, ShowF f) => ShowF (CoAnn f a)
(Show a, ShowF f) => ShowF (Ann f a)
(ShowF f, Show hash) => ShowF (HashAnn hash f)
class ReadF f whereSource
Methods
readPrecF :: Read a => ReadPrec (f a)Source
show/hide Instances
(Read a, ReadF f) => ReadF (Ann f a)
showF :: (ShowF f, Show a) => f a -> StringSource
showsF :: (ShowF f, Show a) => f a -> ShowSSource
Attrib (cofree comonad)
newtype Attrib f a Source

A newtype wrapper around Attr f a so that we can make Attr f an instance of Functor, Foldable and Traversable (and Comonad). This is necessary since Haskell does not allow partial application of type synonyms.

Equivalent to the co-free comonad.

Constructors
Attrib
unAttrib :: Attr f a
show/hide Instances
CoAttrib (free monad)
newtype CoAttrib f a Source
Categorial dual of Attrib. Equivalent to the free monad.
Constructors
CoAttrib
unCoAttrib :: CoAttr f a
show/hide Instances
Produced by Haddock version 2.6.1