monoid-extras-0.7: Various extra monoid-related definitions and utilities

Copyright | (c) 2011-2015 diagrams-core team (see LICENSE)
License | BSD-style (see LICENSE)
Maintainer | diagrams-discuss@googlegroups.com
Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Monoid.Deletable

Description

A monoid transformer that allows deleting information from a concatenation of monoidal values.

Synopsis

- data Deletable m = Deletable Int m Int
- unDelete :: Deletable m -> m
- toDeletable :: m -> Deletable m
- deleteL :: Monoid m => Deletable m
- deleteR :: Monoid m => Deletable m

# Documentation

data Deletable m Source #

If `m` is a `Monoid`, then `Deletable m` (intuitively speaking) adds two distinguished new elements `[` and `]`, such that an occurrence of [ "deletes" everything from it to the next ]. For example,

    abc[def]gh == abcgh

This is all you really need to know to use `Deletable m` values; to understand the actual implementation, read on.

To properly deal with nesting and associativity we need to be able to assign meanings to things like `[[`, `][`, and so on. (We cannot just define, say, `[[ == [`, since then `([[)] == [] == id` but `[([]) == [id == [`.) Formally, elements of `Deletable m` are triples of the form (r, m, l) representing words `]^r m [^l`. When combining two triples (r1, m1, l1) and (r2, m2, l2) there are three cases:

- If l1 == r2 then the [s from the left and ]s from the right exactly cancel, and we are left with (r1, m1 <> m2, l2).
- If l1 < r2 then all of the [s cancel with some of the ]s, but m1 is still inside the remaining ]s and is deleted, yielding (r1 + r2 - l1, m2, l2)
- The remaining case is symmetric with the second.

Constructors

Deletable Int m Int |

#### Instances

Instances details

Functor Deletable Source # |
Instance details Defined in Data.Monoid.Deletable Methods fmap :: (a -> b) -> Deletable a -> Deletable b Source # (<$) :: a -> Deletable b -> Deletable a Source #
Foldable Deletable Source # |

Instance details

Defined in Data.Monoid.Deletable

Methods

fold :: Monoid m => Deletable m -> m Source #

foldMap :: Monoid m => (a -> m) -> Deletable a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Deletable a -> m Source #

foldr :: (a -> b -> b) -> b -> Deletable a -> b Source #

foldr' :: (a -> b -> b) -> b -> Deletable a -> b Source #

foldl :: (b -> a -> b) -> b -> Deletable a -> b Source #

foldl' :: (b -> a -> b) -> b -> Deletable a -> b Source #

foldr1 :: (a -> a -> a) -> Deletable a -> a Source #

foldl1 :: (a -> a -> a) -> Deletable a -> a Source #

toList :: Deletable a -> [a] Source #

null :: Deletable a -> Bool Source #

length :: Deletable a -> Int Source #

elem :: Eq a => a -> Deletable a -> Bool Source #

maximum :: Ord a => Deletable a -> a Source #

minimum :: Ord a => Deletable a -> a Source #

sum :: Num a => Deletable a -> a Source #

product :: Num a => Deletable a -> a Source #

Traversable Deletable Source # |
Instance details Defined in Data.Monoid.Deletable Methods traverse :: Applicative f => (a -> f b) -> Deletable a -> f (Deletable b) Source # sequenceA :: Applicative f => Deletable (f a) -> f (Deletable a) Source # mapM :: Monad m => (a -> m b) -> Deletable a -> m (Deletable b) Source # sequence :: Monad m => Deletable (m a) -> m (Deletable a) Source #
(Semigroup m, Monoid m) => Monoid (Deletable m) Source # |
Instance details Defined in Data.Monoid.Deletable Methods mempty :: Deletable m Source # mappend :: Deletable m -> Deletable m -> Deletable m Source # mconcat :: [Deletable m] -> Deletable m Source #
Semigroup m => Semigroup (Deletable m) Source # |
Instance details Defined in Data.Monoid.Deletable Methods (<>) :: Deletable m -> Deletable m -> Deletable m Source # sconcat :: NonEmpty (Deletable m) -> Deletable m Source # stimes :: Integral b => b -> Deletable m -> Deletable m Source #
Data m => Data (Deletable m) Source # |

Instance details

Defined in Data.Monoid.Deletable

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Deletable m -> c (Deletable m) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Deletable m) Source #

toConstr :: Deletable m -> Constr Source #

dataTypeOf :: Deletable m -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Deletable m)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Deletable m)) Source #

gmapT :: (forall b. Data b => b -> b) -> Deletable m -> Deletable m Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Deletable m -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Deletable m -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Deletable m -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Deletable m -> u Source #

gmapM :: Monad m0 => (forall d. Data d => d -> m0 d) -> Deletable m -> m0 (Deletable m) Source #

gmapMp :: MonadPlus m0 => (forall d. Data d => d -> m0 d) -> Deletable m -> m0 (Deletable m) Source #

gmapMo :: MonadPlus m0 => (forall d. Data d => d -> m0 d) -> Deletable m -> m0 (Deletable m) Source #

Read m => Read (Deletable m) Source # |
Instance details Defined in Data.Monoid.Deletable Methods readsPrec :: Int -> ReadS (Deletable m) Source # readList :: ReadS [Deletable m] Source # readPrec :: ReadPrec (Deletable m) Source # readListPrec :: ReadPrec [Deletable m] Source #
Show m => Show (Deletable m) Source # |
Instance details Defined in Data.Monoid.Deletable Methods showsPrec :: Int -> Deletable m -> ShowS Source # show :: Deletable m -> String Source # showList :: [Deletable m] -> ShowS Source #

unDelete :: Deletable m -> m Source #

Project the wrapped value out of a `Deletable` value.

toDeletable :: m -> Deletable m Source #

Inject a value into a `Deletable` wrapper. Satisfies the property

    unDelete . toDeletable === id

deleteL :: Monoid m => Deletable m Source #

A "left bracket", which causes everything between it and the next right bracket to be deleted.

deleteR :: Monoid m => Deletable m Source #

A "right bracket", denoting the end of the section that should be deleted.