Safe Haskell | Safe |
---|---|

Language | Haskell2010 |

This modules exposes a type representing the fixpoint of a functor type, paired with an annotation. It exports the recursion-schemes instances for this type and a few specific utility functions.

# Motivation

Suppose one has an Abstract Syntax Tree (AST) for the lambda calculus:

data Term = Var String | App Term Term | Lam String Term

Such a type can easily be used with the recursion-schemes library, but it is not always convenient to use this type. It is often the case that one wants to add extra informations to every node of an AST, such as location or type information. In this case, instead of adding those informations as an extra-field to all data constructors, one could prefer to represent terms as a record of a descriptor and the information present at every node, like so:

data TermDesc = Var String | App Term Term | Lam String Term data Term = Term { termDesc :: TermDesc , termTyp :: Typ , termLoc :: Loc , ... }

This library implements this general pattern through the `Annot`

type,
representing the fixpoint of a functor type, paired with some annotation. In
this setting, the above example would be represented like so:

data TermDesc r = Var String | App r r | Lam String r data TermAnn = TermAnn { termTyp :: Typ , termLoc :: Loc , ... } type Term = Annot TermDesc TermAnn

## Synopsis

- data Annot f a = Annot a (f (Annot f a))
- strip :: Annot f a -> f (Annot f a)
- annotation :: Annot f a -> a
- annotate :: Functor f => (f (Annot f a) -> a) -> Fix f -> Annot f a
- annotateRec :: Recursive t => (Base t (Annot (Base t) a) -> a) -> t -> Annot (Base t) a
- deannotate :: Functor f => Annot f a -> Fix f
- deannotateCorec :: Corecursive t => Annot (Base t) a -> t
- cataAnn :: Functor f => (a -> f b -> b) -> Annot f a -> b
- paraAnn :: Functor f => (a -> f (Annot f a, b) -> b) -> Annot f a -> b

# Documentation

The fixpoint type of functor `f`

, with some annotation `a`

.

## Instances

Functor f => Functor (Annot f) Source # | |

Foldable f => Foldable (Annot f) Source # | |

Defined in Data.Functor.Annotated fold :: Monoid m => Annot f m -> m # foldMap :: Monoid m => (a -> m) -> Annot f a -> m # foldr :: (a -> b -> b) -> b -> Annot f a -> b # foldr' :: (a -> b -> b) -> b -> Annot f a -> b # foldl :: (b -> a -> b) -> b -> Annot f a -> b # foldl' :: (b -> a -> b) -> b -> Annot f a -> b # foldr1 :: (a -> a -> a) -> Annot f a -> a # foldl1 :: (a -> a -> a) -> Annot f a -> a # elem :: Eq a => a -> Annot f a -> Bool # maximum :: Ord a => Annot f a -> a # minimum :: Ord a => Annot f a -> a # | |

Traversable f => Traversable (Annot f) Source # | |

Generic (Annot f a) Source # | |

Functor f => Recursive (Annot f a) Source # | |

Defined in Data.Functor.Annotated project :: Annot f a -> Base (Annot f a) (Annot f a) # cata :: (Base (Annot f a) a0 -> a0) -> Annot f a -> a0 # para :: (Base (Annot f a) (Annot f a, a0) -> a0) -> Annot f a -> a0 # gpara :: (Corecursive (Annot f a), Comonad w) => (forall b. Base (Annot f a) (w b) -> w (Base (Annot f a) b)) -> (Base (Annot f a) (EnvT (Annot f a) w a0) -> a0) -> Annot f a -> a0 # prepro :: Corecursive (Annot f a) => (forall b. Base (Annot f a) b -> Base (Annot f a) b) -> (Base (Annot f a) a0 -> a0) -> Annot f a -> a0 # gprepro :: (Corecursive (Annot f a), Comonad w) => (forall b. Base (Annot f a) (w b) -> w (Base (Annot f a) b)) -> (forall c. Base (Annot f a) c -> Base (Annot f a) c) -> (Base (Annot f a) (w a0) -> a0) -> Annot f a -> a0 # | |

type Rep (Annot f a) Source # | |

Defined in Data.Functor.Annotated type Rep (Annot f a) = D1 (MetaData "Annot" "Data.Functor.Annotated" "annotated-fix-0.1.0.0-1iukNPhNY3oIl0on2YwNeK" False) (C1 (MetaCons "Annot" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (f (Annot f a))))) | |

type Base (Annot f a) Source # | |

Defined in Data.Functor.Annotated |

## Annotating and deannotating

annotation :: Annot f a -> a Source #

Extracts the annotation

annotate :: Functor f => (f (Annot f a) -> a) -> Fix f -> Annot f a Source #

Annotates all the node of a functor's fixpoint value

deannotateCorec :: Corecursive t => Annot (Base t) a -> t Source #

Generalized version of `deannotate`

for instances of `Corecursive`