fixplate-0.1.8: Uniplate-style generic traversals for optionally annotated fixed-point types.

Safe HaskellSafe
LanguageHaskell2010

Data.Generics.Fixplate.Base

Contents

Description

The core types of Fixplate.

Synopsis

Documentation

newtype Mu f Source #

The fixed-point type.

Constructors

Fix 

Fields

Instances
EqF f => Eq (Mu f) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

(==) :: Mu f -> Mu f -> Bool #

(/=) :: Mu f -> Mu f -> Bool #

OrdF f => Ord (Mu f) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

compare :: Mu f -> Mu f -> Ordering #

(<) :: Mu f -> Mu f -> Bool #

(<=) :: Mu f -> Mu f -> Bool #

(>) :: Mu f -> Mu f -> Bool #

(>=) :: Mu f -> Mu f -> Bool #

max :: Mu f -> Mu f -> Mu f #

min :: Mu f -> Mu f -> Mu f #

ReadF f => Read (Mu f) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

ShowF f => Show (Mu f) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

showsPrec :: Int -> Mu f -> ShowS #

show :: Mu f -> String #

showList :: [Mu f] -> ShowS #

isAtom :: Foldable f => Mu f -> Bool Source #

We call a tree "atomic" if it has no subtrees.

Annotations

data Ann f a b Source #

Type of annotations

Constructors

Ann 

Fields

  • attr :: a

    the annotation

  • unAnn :: f b

    the original functor

Instances
Functor f => Functor (Ann f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

fmap :: (a0 -> b) -> Ann f a a0 -> Ann f a b #

(<$) :: a0 -> Ann f a b -> Ann f a a0 #

Foldable f => Foldable (Ann f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

fold :: Monoid m => Ann f a m -> m #

foldMap :: Monoid m => (a0 -> m) -> Ann f a a0 -> m #

foldr :: (a0 -> b -> b) -> b -> Ann f a a0 -> b #

foldr' :: (a0 -> b -> b) -> b -> Ann f a a0 -> b #

foldl :: (b -> a0 -> b) -> b -> Ann f a a0 -> b #

foldl' :: (b -> a0 -> b) -> b -> Ann f a a0 -> b #

foldr1 :: (a0 -> a0 -> a0) -> Ann f a a0 -> a0 #

foldl1 :: (a0 -> a0 -> a0) -> Ann f a a0 -> a0 #

toList :: Ann f a a0 -> [a0] #

null :: Ann f a a0 -> Bool #

length :: Ann f a a0 -> Int #

elem :: Eq a0 => a0 -> Ann f a a0 -> Bool #

maximum :: Ord a0 => Ann f a a0 -> a0 #

minimum :: Ord a0 => Ann f a a0 -> a0 #

sum :: Num a0 => Ann f a a0 -> a0 #

product :: Num a0 => Ann f a a0 -> a0 #

Traversable f => Traversable (Ann f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

traverse :: Applicative f0 => (a0 -> f0 b) -> Ann f a a0 -> f0 (Ann f a b) #

sequenceA :: Applicative f0 => Ann f a (f0 a0) -> f0 (Ann f a a0) #

mapM :: Monad m => (a0 -> m b) -> Ann f a a0 -> m (Ann f a b) #

sequence :: Monad m => Ann f a (m a0) -> m (Ann f a a0) #

(Read a, ReadF f) => ReadF (Ann f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

readPrecF :: Read a0 => ReadPrec (Ann f a a0) Source #

(Show a, ShowF f) => ShowF (Ann f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

showsPrecF :: Show a0 => Int -> Ann f a a0 -> ShowS Source #

(Ord a, OrdF f) => OrdF (Ann f a) Source #

NOTE: The OrdF instance for annotations first compares the annotations, and then the functor part. If this is not the desired behaviour (it's not clear to me at the moment what is the good default here), you can use the standard newtype trick to define a new behaviour.

Instance details

Defined in Data.Generics.Fixplate.Base

Methods

compareF :: Ord a0 => Ann f a a0 -> Ann f a a0 -> Ordering Source #

(Eq a, EqF f) => EqF (Ann f a) Source #

NOTE: The EqF instance for annotations compares both the annotations and the original part.

Instance details

Defined in Data.Generics.Fixplate.Base

Methods

equalF :: Eq a0 => Ann f a a0 -> Ann f a a0 -> Bool Source #

(Eq a, Eq (f b)) => Eq (Ann f a b) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

(==) :: Ann f a b -> Ann f a b -> Bool #

(/=) :: Ann f a b -> Ann f a b -> Bool #

(Ord a, Ord (f b)) => Ord (Ann f a b) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

compare :: Ann f a b -> Ann f a b -> Ordering #

(<) :: Ann f a b -> Ann f a b -> Bool #

(<=) :: Ann f a b -> Ann f a b -> Bool #

(>) :: Ann f a b -> Ann f a b -> Bool #

(>=) :: Ann f a b -> Ann f a b -> Bool #

max :: Ann f a b -> Ann f a b -> Ann f a b #

min :: Ann f a b -> Ann f a b -> Ann f a b #

(Show a, Show (f b)) => Show (Ann f a b) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

showsPrec :: Int -> Ann f a b -> ShowS #

show :: Ann f a b -> String #

showList :: [Ann f a b] -> ShowS #

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 e Source #

Lifting natural transformations to annotations.

Co-annotations

data CoAnn f a b Source #

Categorical dual of Ann.

Constructors

Pure a 
CoAnn (f b) 
Instances
Functor f => Functor (CoAnn f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

fmap :: (a0 -> b) -> CoAnn f a a0 -> CoAnn f a b #

(<$) :: a0 -> CoAnn f a b -> CoAnn f a a0 #

Foldable f => Foldable (CoAnn f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

fold :: Monoid m => CoAnn f a m -> m #

foldMap :: Monoid m => (a0 -> m) -> CoAnn f a a0 -> m #

foldr :: (a0 -> b -> b) -> b -> CoAnn f a a0 -> b #

foldr' :: (a0 -> b -> b) -> b -> CoAnn f a a0 -> b #

foldl :: (b -> a0 -> b) -> b -> CoAnn f a a0 -> b #

foldl' :: (b -> a0 -> b) -> b -> CoAnn f a a0 -> b #

foldr1 :: (a0 -> a0 -> a0) -> CoAnn f a a0 -> a0 #

foldl1 :: (a0 -> a0 -> a0) -> CoAnn f a a0 -> a0 #

toList :: CoAnn f a a0 -> [a0] #

null :: CoAnn f a a0 -> Bool #

length :: CoAnn f a a0 -> Int #

elem :: Eq a0 => a0 -> CoAnn f a a0 -> Bool #

maximum :: Ord a0 => CoAnn f a a0 -> a0 #

minimum :: Ord a0 => CoAnn f a a0 -> a0 #

sum :: Num a0 => CoAnn f a a0 -> a0 #

product :: Num a0 => CoAnn f a a0 -> a0 #

Traversable f => Traversable (CoAnn f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

traverse :: Applicative f0 => (a0 -> f0 b) -> CoAnn f a a0 -> f0 (CoAnn f a b) #

sequenceA :: Applicative f0 => CoAnn f a (f0 a0) -> f0 (CoAnn f a a0) #

mapM :: Monad m => (a0 -> m b) -> CoAnn f a a0 -> m (CoAnn f a b) #

sequence :: Monad m => CoAnn f a (m a0) -> m (CoAnn f a a0) #

(Show a, ShowF f) => ShowF (CoAnn f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

showsPrecF :: Show a0 => Int -> CoAnn f a a0 -> ShowS Source #

(Ord a, OrdF f) => OrdF (CoAnn f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

compareF :: Ord a0 => CoAnn f a a0 -> CoAnn f a a0 -> Ordering Source #

(Eq a, EqF f) => EqF (CoAnn f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

equalF :: Eq a0 => CoAnn f a a0 -> CoAnn f a a0 -> Bool Source #

(Eq a, Eq (f b)) => Eq (CoAnn f a b) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

(==) :: CoAnn f a b -> CoAnn f a b -> Bool #

(/=) :: CoAnn f a b -> CoAnn f a b -> Bool #

(Ord a, Ord (f b)) => Ord (CoAnn f a b) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

compare :: CoAnn f a b -> CoAnn f a b -> Ordering #

(<) :: CoAnn f a b -> CoAnn f a b -> Bool #

(<=) :: CoAnn f a b -> CoAnn f a b -> Bool #

(>) :: CoAnn f a b -> CoAnn f a b -> Bool #

(>=) :: CoAnn f a b -> CoAnn f a b -> Bool #

max :: CoAnn f a b -> CoAnn f a b -> CoAnn f a b #

min :: CoAnn f a b -> CoAnn f a b -> CoAnn f a b #

(Show a, Show (f b)) => Show (CoAnn f a b) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

showsPrec :: Int -> CoAnn f a b -> ShowS #

show :: CoAnn f a b -> String #

showList :: [CoAnn f a b] -> ShowS #

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 e Source #

Lifting natural transformations to annotations.

Annotated trees

attribute :: Attr f a -> a Source #

The attribute of the root node.

forget :: Functor f => Attr f a -> Mu f Source #

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 
Instances
Eq Hole Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

(==) :: Hole -> Hole -> Bool #

(/=) :: Hole -> Hole -> Bool #

Ord Hole Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

compare :: Hole -> Hole -> Ordering #

(<) :: Hole -> Hole -> Bool #

(<=) :: Hole -> Hole -> Bool #

(>) :: Hole -> Hole -> Bool #

(>=) :: Hole -> Hole -> Bool #

max :: Hole -> Hole -> Hole #

min :: Hole -> Hole -> Hole #

Higher-order type classes

class EqF f where Source #

"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 -> Bool Source #

Instances
(Eq a, EqF f) => EqF (CoAnn f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

equalF :: Eq a0 => CoAnn f a a0 -> CoAnn f a a0 -> Bool Source #

(Eq a, EqF f) => EqF (Ann f a) Source #

NOTE: The EqF instance for annotations compares both the annotations and the original part.

Instance details

Defined in Data.Generics.Fixplate.Base

Methods

equalF :: Eq a0 => Ann f a a0 -> Ann f a a0 -> Bool Source #

(Eq hash, EqF f) => EqF (HashAnn hash f) Source # 
Instance details

Defined in Data.Generics.Fixplate.Hash

Methods

equalF :: Eq a => HashAnn hash f a -> HashAnn hash f a -> Bool Source #

(EqF f, EqF g) => EqF (f :*: g) Source # 
Instance details

Defined in Data.Generics.Fixplate.Functor

Methods

equalF :: Eq a => (f :*: g) a -> (f :*: g) a -> Bool Source #

(EqF f, EqF g) => EqF (f :+: g) Source # 
Instance details

Defined in Data.Generics.Fixplate.Functor

Methods

equalF :: Eq a => (f :+: g) a -> (f :+: g) a -> Bool Source #

class EqF f => OrdF f where Source #

Methods

compareF :: Ord a => f a -> f a -> Ordering Source #

Instances
(Ord a, OrdF f) => OrdF (CoAnn f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

compareF :: Ord a0 => CoAnn f a a0 -> CoAnn f a a0 -> Ordering Source #

(Ord a, OrdF f) => OrdF (Ann f a) Source #

NOTE: The OrdF instance for annotations first compares the annotations, and then the functor part. If this is not the desired behaviour (it's not clear to me at the moment what is the good default here), you can use the standard newtype trick to define a new behaviour.

Instance details

Defined in Data.Generics.Fixplate.Base

Methods

compareF :: Ord a0 => Ann f a a0 -> Ann f a a0 -> Ordering Source #

(Ord hash, OrdF f) => OrdF (HashAnn hash f) Source # 
Instance details

Defined in Data.Generics.Fixplate.Hash

Methods

compareF :: Ord a => HashAnn hash f a -> HashAnn hash f a -> Ordering Source #

(OrdF f, OrdF g) => OrdF (f :*: g) Source # 
Instance details

Defined in Data.Generics.Fixplate.Functor

Methods

compareF :: Ord a => (f :*: g) a -> (f :*: g) a -> Ordering Source #

(OrdF f, OrdF g) => OrdF (f :+: g) Source # 
Instance details

Defined in Data.Generics.Fixplate.Functor

Methods

compareF :: Ord a => (f :+: g) a -> (f :+: g) a -> Ordering Source #

class ShowF f where Source #

Methods

showsPrecF :: Show a => Int -> f a -> ShowS Source #

Instances
(Show a, ShowF f) => ShowF (CoAnn f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

showsPrecF :: Show a0 => Int -> CoAnn f a a0 -> ShowS Source #

(Show a, ShowF f) => ShowF (Ann f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

showsPrecF :: Show a0 => Int -> Ann f a a0 -> ShowS Source #

(ShowF f, Show hash) => ShowF (HashAnn hash f) Source # 
Instance details

Defined in Data.Generics.Fixplate.Hash

Methods

showsPrecF :: Show a => Int -> HashAnn hash f a -> ShowS Source #

(ShowF f, ShowF g) => ShowF (f :*: g) Source # 
Instance details

Defined in Data.Generics.Fixplate.Functor

Methods

showsPrecF :: Show a => Int -> (f :*: g) a -> ShowS Source #

(ShowF f, ShowF g) => ShowF (f :+: g) Source # 
Instance details

Defined in Data.Generics.Fixplate.Functor

Methods

showsPrecF :: Show a => Int -> (f :+: g) a -> ShowS Source #

class ReadF f where Source #

Methods

readPrecF :: Read a => ReadPrec (f a) Source #

Instances
(Read a, ReadF f) => ReadF (Ann f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

readPrecF :: Read a0 => ReadPrec (Ann f a a0) Source #

showF :: (ShowF f, Show a) => f a -> String Source #

showsF :: (ShowF f, Show a) => f a -> ShowS Source #

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 

Fields

Instances
Functor f => Functor (Attrib f) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

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

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

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

Defined in Data.Generics.Fixplate.Base

Methods

fold :: Monoid m => Attrib f m -> m #

foldMap :: Monoid m => (a -> m) -> Attrib f a -> m #

foldr :: (a -> b -> b) -> b -> Attrib f a -> b #

foldr' :: (a -> b -> b) -> b -> Attrib f a -> b #

foldl :: (b -> a -> b) -> b -> Attrib f a -> b #

foldl' :: (b -> a -> b) -> b -> Attrib f a -> b #

foldr1 :: (a -> a -> a) -> Attrib f a -> a #

foldl1 :: (a -> a -> a) -> Attrib f a -> a #

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

null :: Attrib f a -> Bool #

length :: Attrib f a -> Int #

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

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

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

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

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

Traversable f => Traversable (Attrib f) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

traverse :: Applicative f0 => (a -> f0 b) -> Attrib f a -> f0 (Attrib f b) #

sequenceA :: Applicative f0 => Attrib f (f0 a) -> f0 (Attrib f a) #

mapM :: Monad m => (a -> m b) -> Attrib f a -> m (Attrib f b) #

sequence :: Monad m => Attrib f (m a) -> m (Attrib f a) #

(ShowF f, Show a) => Show (Attrib f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

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

show :: Attrib f a -> String #

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

CoAttrib (free monad)

newtype CoAttrib f a Source #

Categorial dual of Attrib. Equivalent to the free monad.

Constructors

CoAttrib 

Fields

Instances
Functor f => Monad (CoAttrib f) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

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

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

return :: a -> CoAttrib f a #

fail :: String -> CoAttrib f a #

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

Defined in Data.Generics.Fixplate.Base

Methods

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

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

Functor f => Applicative (CoAttrib f) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

pure :: a -> CoAttrib f a #

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

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

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

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

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

Defined in Data.Generics.Fixplate.Base

Methods

fold :: Monoid m => CoAttrib f m -> m #

foldMap :: Monoid m => (a -> m) -> CoAttrib f a -> m #

foldr :: (a -> b -> b) -> b -> CoAttrib f a -> b #

foldr' :: (a -> b -> b) -> b -> CoAttrib f a -> b #

foldl :: (b -> a -> b) -> b -> CoAttrib f a -> b #

foldl' :: (b -> a -> b) -> b -> CoAttrib f a -> b #

foldr1 :: (a -> a -> a) -> CoAttrib f a -> a #

foldl1 :: (a -> a -> a) -> CoAttrib f a -> a #

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

null :: CoAttrib f a -> Bool #

length :: CoAttrib f a -> Int #

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

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

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

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

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

Traversable f => Traversable (CoAttrib f) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

traverse :: Applicative f0 => (a -> f0 b) -> CoAttrib f a -> f0 (CoAttrib f b) #

sequenceA :: Applicative f0 => CoAttrib f (f0 a) -> f0 (CoAttrib f a) #

mapM :: Monad m => (a -> m b) -> CoAttrib f a -> m (CoAttrib f b) #

sequence :: Monad m => CoAttrib f (m a) -> m (CoAttrib f a) #

(ShowF f, Show a) => Show (CoAttrib f a) Source # 
Instance details

Defined in Data.Generics.Fixplate.Base

Methods

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

show :: CoAttrib f a -> String #

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