{-
    Copyright 2023 Mario Blazevic

    License: BSD3 (see BSD3-LICENSE.txt file)
-}

-- | This module defines the monoid transformer data type 'Shadowed'.
{-# LANGUAGE Haskell2010, DeriveDataTypeable #-}

module Data.Monoid.Instances.PrefixMemory (
   Shadowed, shadowed, content, prefix
   )
where

import Control.Applicative -- (Applicative(..))
import qualified Data.List as List
import Data.String (IsString(fromString))

import Data.Data (Data, Typeable)
import Data.Semigroup (Semigroup(..))
import Data.Monoid (Monoid(..), Endo(..))
import Data.Semigroup.Cancellative (LeftReductive(..), RightReductive(..))
import Data.Semigroup.Factorial (Factorial(..), StableFactorial)
import Data.Monoid.GCD (LeftGCDMonoid(..), RightGCDMonoid(..))
import Data.Monoid.Null (MonoidNull(null), PositiveMonoid)
import Data.Monoid.Factorial (FactorialMonoid(..))
import Data.Monoid.Textual (TextualMonoid(..))
import qualified Data.Semigroup.Factorial as Factorial
import qualified Data.Monoid.Factorial as Factorial
import qualified Data.Monoid.Textual as Textual

import Prelude hiding (all, any, break, filter, foldl, foldl1, foldr, foldr1, lines, map, concatMap,
                       length, null, reverse, scanl, scanr, scanl1, scanr1, span, splitAt)

-- | Monoid transformer that keeps track of the former 'prefix' of its 'content'. All functions that return a suffix
-- of their argument, such as 'stripPrefix' or 'commonSuffix', preserve the discarded 'prefix'.
data Shadowed m = Shadowed{forall m. Shadowed m -> m
prefix :: !m,
                           -- ^ used to precede the 'content' but has been consumed
                           forall m. Shadowed m -> m
content :: !m
                           -- ^ the present value
                          } deriving (Shadowed m -> DataType
Shadowed m -> Constr
forall {m}. Data m => Typeable (Shadowed m)
forall m. Data m => Shadowed m -> DataType
forall m. Data m => Shadowed m -> Constr
forall m.
Data m =>
(forall b. Data b => b -> b) -> Shadowed m -> Shadowed m
forall m u.
Data m =>
Int -> (forall d. Data d => d -> u) -> Shadowed m -> u
forall m u.
Data m =>
(forall d. Data d => d -> u) -> Shadowed m -> [u]
forall m r r'.
Data m =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Shadowed m -> r
forall m r r'.
Data m =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Shadowed m -> r
forall m (m :: * -> *).
(Data m, Monad m) =>
(forall d. Data d => d -> m d) -> Shadowed m -> m (Shadowed m)
forall m (m :: * -> *).
(Data m, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Shadowed m -> m (Shadowed m)
forall m (c :: * -> *).
Data m =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Shadowed m)
forall m (c :: * -> *).
Data m =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Shadowed m -> c (Shadowed m)
forall m (t :: * -> *) (c :: * -> *).
(Data m, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Shadowed m))
forall m (t :: * -> * -> *) (c :: * -> *).
(Data m, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Shadowed m))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Shadowed m)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Shadowed m -> c (Shadowed m)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Shadowed m))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Shadowed m -> m (Shadowed m)
$cgmapMo :: forall m (m :: * -> *).
(Data m, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Shadowed m -> m (Shadowed m)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Shadowed m -> m (Shadowed m)
$cgmapMp :: forall m (m :: * -> *).
(Data m, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Shadowed m -> m (Shadowed m)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Shadowed m -> m (Shadowed m)
$cgmapM :: forall m (m :: * -> *).
(Data m, Monad m) =>
(forall d. Data d => d -> m d) -> Shadowed m -> m (Shadowed m)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Shadowed m -> u
$cgmapQi :: forall m u.
Data m =>
Int -> (forall d. Data d => d -> u) -> Shadowed m -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Shadowed m -> [u]
$cgmapQ :: forall m u.
Data m =>
(forall d. Data d => d -> u) -> Shadowed m -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Shadowed m -> r
$cgmapQr :: forall m r r'.
Data m =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Shadowed m -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Shadowed m -> r
$cgmapQl :: forall m r r'.
Data m =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Shadowed m -> r
gmapT :: (forall b. Data b => b -> b) -> Shadowed m -> Shadowed m
$cgmapT :: forall m.
Data m =>
(forall b. Data b => b -> b) -> Shadowed m -> Shadowed m
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Shadowed m))
$cdataCast2 :: forall m (t :: * -> * -> *) (c :: * -> *).
(Data m, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Shadowed m))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Shadowed m))
$cdataCast1 :: forall m (t :: * -> *) (c :: * -> *).
(Data m, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Shadowed m))
dataTypeOf :: Shadowed m -> DataType
$cdataTypeOf :: forall m. Data m => Shadowed m -> DataType
toConstr :: Shadowed m -> Constr
$ctoConstr :: forall m. Data m => Shadowed m -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Shadowed m)
$cgunfold :: forall m (c :: * -> *).
Data m =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Shadowed m)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Shadowed m -> c (Shadowed m)
$cgfoldl :: forall m (c :: * -> *).
Data m =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Shadowed m -> c (Shadowed m)
Data, Typeable)

-- | The constructor of a 'Shadowed' monoid, with the initial @prefix = null@
shadowed :: Monoid m => m -> Shadowed m
shadowed :: forall m. Monoid m => m -> Shadowed m
shadowed = forall m. m -> m -> Shadowed m
Shadowed forall a. Monoid a => a
mempty

instance Eq m => Eq (Shadowed m) where
   Shadowed{content :: forall m. Shadowed m -> m
content = m
a} == :: Shadowed m -> Shadowed m -> Bool
== Shadowed{content :: forall m. Shadowed m -> m
content = m
b} = m
a forall a. Eq a => a -> a -> Bool
== m
b

instance Ord m => Ord (Shadowed m) where
   compare :: Shadowed m -> Shadowed m -> Ordering
compare Shadowed{content :: forall m. Shadowed m -> m
content= m
a} Shadowed{content :: forall m. Shadowed m -> m
content= m
b} = forall a. Ord a => a -> a -> Ordering
compare m
a m
b

instance (MonoidNull m, Show m) => Show (Shadowed m) where
   showsPrec :: Int -> Shadowed m -> ShowS
showsPrec Int
prec (Shadowed m
p m
c) String
rest
      | forall m. MonoidNull m => m -> Bool
null m
p = forall a. Show a => Int -> a -> ShowS
showsPrec Int
prec m
c String
rest
      | Bool
otherwise = String
"Shadowed{prefix=" forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> ShowS
shows m
p (String
", content=" forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> ShowS
shows m
c (String
"}" forall a. Semigroup a => a -> a -> a
<> String
rest))

instance (MonoidNull m, StableFactorial m) => Semigroup (Shadowed m) where
   Shadowed m
p1 m
c1 <> :: Shadowed m -> Shadowed m -> Shadowed m
<> m2 :: Shadowed m
m2@Shadowed{content :: forall m. Shadowed m -> m
content = m
c2}
      | forall m. MonoidNull m => m -> Bool
null m
c1 Bool -> Bool -> Bool
&& forall m. MonoidNull m => m -> Bool
null m
p1 = Shadowed m
m2
      | Bool
otherwise = forall m. m -> m -> Shadowed m
Shadowed m
p1 (m
c1 forall a. Semigroup a => a -> a -> a
<> m
c2)
   {-# INLINE (<>) #-}

instance (MonoidNull m, StableFactorial m) => Monoid (Shadowed m) where
   mempty :: Shadowed m
mempty = forall m. Monoid m => m -> Shadowed m
shadowed forall a. Monoid a => a
mempty
   mappend :: Shadowed m -> Shadowed m -> Shadowed m
mappend = forall a. Semigroup a => a -> a -> a
(<>)
   {-# INLINE mempty #-}
   {-# INLINE mappend #-}

instance (MonoidNull m, StableFactorial m) => MonoidNull (Shadowed m) where
   null :: Shadowed m -> Bool
null = forall m. MonoidNull m => m -> Bool
null forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. Shadowed m -> m
content
   {-# INLINE null #-}

instance (PositiveMonoid m, StableFactorial m) => PositiveMonoid (Shadowed m)

instance (MonoidNull m, StableFactorial m, LeftReductive m) => LeftReductive (Shadowed m) where
   Shadowed m
t1 isPrefixOf :: Shadowed m -> Shadowed m -> Bool
`isPrefixOf` Shadowed m
t2 = forall m. Shadowed m -> m
content Shadowed m
t1 forall m. LeftReductive m => m -> m -> Bool
`isPrefixOf` forall m. Shadowed m -> m
content Shadowed m
t2
   stripPrefix :: Shadowed m -> Shadowed m -> Maybe (Shadowed m)
stripPrefix (Shadowed m
_ m
c1) (Shadowed m
p m
c2) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall m. m -> m -> Shadowed m
Shadowed (m
p forall a. Semigroup a => a -> a -> a
<> m
c1)) (forall m. LeftReductive m => m -> m -> Maybe m
stripPrefix m
c1 m
c2)
   {-# INLINE isPrefixOf #-}
   {-# INLINE stripPrefix #-}

instance (Eq m, StableFactorial m, FactorialMonoid m, LeftGCDMonoid m) => LeftGCDMonoid (Shadowed m) where
   stripCommonPrefix :: Shadowed m -> Shadowed m -> (Shadowed m, Shadowed m, Shadowed m)
stripCommonPrefix (Shadowed m
p1 m
c1) (Shadowed m
p2 m
c2) =
      (forall m. m -> m -> Shadowed m
Shadowed m
prefix' m
common, forall m. m -> m -> Shadowed m
Shadowed (m
p1 forall a. Semigroup a => a -> a -> a
<> m
common) m
c1', forall m. m -> m -> Shadowed m
Shadowed (m
p2 forall a. Semigroup a => a -> a -> a
<> m
common) m
c2')
      where (m
common, m
c1', m
c2') = forall m. LeftGCDMonoid m => m -> m -> (m, m, m)
stripCommonPrefix m
c1 m
c2
            prefix' :: m
prefix' = if m
p1 forall a. Eq a => a -> a -> Bool
== m
p2 then m
p1 forall a. Semigroup a => a -> a -> a
<> m
common else m
common
   {-# INLINE stripCommonPrefix #-}

instance (StableFactorial m, FactorialMonoid m, RightReductive m) => RightReductive (Shadowed m) where
   isSuffixOf :: Shadowed m -> Shadowed m -> Bool
isSuffixOf (Shadowed m
_ m
c1) (Shadowed m
_ m
c2) = forall m. RightReductive m => m -> m -> Bool
isSuffixOf m
c1 m
c2
   stripSuffix :: Shadowed m -> Shadowed m -> Maybe (Shadowed m)
stripSuffix (Shadowed m
_ m
c1) (Shadowed m
p m
c2) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall m. m -> m -> Shadowed m
Shadowed m
p) (forall m. RightReductive m => m -> m -> Maybe m
stripSuffix m
c1 m
c2)
   {-# INLINE isSuffixOf #-}
   {-# INLINE stripSuffix #-}

instance (StableFactorial m, FactorialMonoid m, RightGCDMonoid m) => RightGCDMonoid (Shadowed m) where
   commonSuffix :: Shadowed m -> Shadowed m -> Shadowed m
commonSuffix (Shadowed m
_ m
c1) (Shadowed m
_ m
c2) = forall m. Monoid m => m -> Shadowed m
shadowed m
suffix
      where suffix :: m
suffix = forall m. RightGCDMonoid m => m -> m -> m
commonSuffix m
c1 m
c2
   stripCommonSuffix :: Shadowed m -> Shadowed m -> (Shadowed m, Shadowed m, Shadowed m)
stripCommonSuffix (Shadowed m
p1 m
c1) (Shadowed m
p2 m
c2) =
      (forall m. m -> m -> Shadowed m
Shadowed m
p1 m
c1', forall m. m -> m -> Shadowed m
Shadowed m
p2 m
c2',
       forall m. Monoid m => m -> Shadowed m
shadowed m
suffix)
      where (m
c1', m
c2', m
suffix) = forall m. RightGCDMonoid m => m -> m -> (m, m, m)
stripCommonSuffix m
c1 m
c2
   {-# INLINE commonSuffix #-}
   {-# INLINE stripCommonSuffix #-}

instance (FactorialMonoid m, StableFactorial m) => Factorial (Shadowed m) where
   factors :: Shadowed m -> [Shadowed m]
factors (Shadowed m
p m
c) = m -> Shadowed m
rewrap forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. [a] -> [a]
List.tail (forall m. FactorialMonoid m => m -> [m]
inits m
c)
      where rewrap :: m -> Shadowed m
rewrap m
t
               | Just (m
p', m
prime) <- forall m. FactorialMonoid m => m -> Maybe (m, m)
splitPrimeSuffix m
t = forall m. m -> m -> Shadowed m
Shadowed (m
p forall a. Semigroup a => a -> a -> a
<> m
p') m
prime
               | Bool
otherwise = forall a. HasCallStack => String -> a
error String
"all (not . null) . tail . inits"
   primePrefix :: Shadowed m -> Shadowed m
primePrefix (Shadowed m
p m
c) = forall m. m -> m -> Shadowed m
Shadowed m
p (forall m. Factorial m => m -> m
primePrefix m
c)
   foldl :: forall a. (a -> Shadowed m -> a) -> a -> Shadowed m -> a
foldl a -> Shadowed m -> a
f a
a0 (Shadowed m
p0 m
c0) = forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall m a. Factorial m => (a -> m -> a) -> a -> m -> a
Factorial.foldl (a, m) -> m -> (a, m)
f' (a
a0, m
p0) m
c0
      where f' :: (a, m) -> m -> (a, m)
f' (a
a, m
p) m
c = (a -> Shadowed m -> a
f a
a (forall m. m -> m -> Shadowed m
Shadowed m
p m
c), m
p forall a. Semigroup a => a -> a -> a
<> m
c)
   foldl' :: forall a. (a -> Shadowed m -> a) -> a -> Shadowed m -> a
foldl' a -> Shadowed m -> a
f a
a0 (Shadowed m
p0 m
c0) = forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall m a. Factorial m => (a -> m -> a) -> a -> m -> a
Factorial.foldl' (a, m) -> m -> (a, m)
f' (a
a0, m
p0) m
c0
      where f' :: (a, m) -> m -> (a, m)
f' (a
a, m
p) m
c = ((,) forall a b. (a -> b) -> a -> b
$! a -> Shadowed m -> a
f a
a (forall m. m -> m -> Shadowed m
Shadowed m
p m
c)) forall a b. (a -> b) -> a -> b
$! m
p forall a. Semigroup a => a -> a -> a
<> m
c
   foldr :: forall a. (Shadowed m -> a -> a) -> a -> Shadowed m -> a
foldr Shadowed m -> a -> a
f a
a0 (Shadowed m
p0 m
c0) = forall m a. Factorial m => (m -> a -> a) -> a -> m -> a
Factorial.foldr m -> (m -> a) -> m -> a
f' (forall a b. a -> b -> a
const a
a0) m
c0 m
p0
      where f' :: m -> (m -> a) -> m -> a
f' m
c m -> a
cont m
p = Shadowed m -> a -> a
f (forall m. m -> m -> Shadowed m
Shadowed m
p m
c) (m -> a
cont forall a b. (a -> b) -> a -> b
$! m
p forall a. Semigroup a => a -> a -> a
<> m
c)
   foldMap :: forall n. Monoid n => (Shadowed m -> n) -> Shadowed m -> n
foldMap Shadowed m -> n
f (Shadowed m
p0 m
c) = forall a. Endo a -> a -> a
appEndo (forall m n. (Factorial m, Monoid n) => (m -> n) -> m -> n
Factorial.foldMap m -> Endo (m -> n)
f' m
c) (forall a b. a -> b -> a
const forall a. Monoid a => a
mempty) m
p0
      where -- f' :: m -> Endo (Int -> m)
            f' :: m -> Endo (m -> n)
f' m
prime = forall a. (a -> a) -> Endo a
Endo (\m -> n
cont m
p-> Shadowed m -> n
f (forall m. m -> m -> Shadowed m
Shadowed m
p m
prime) forall a. Monoid a => a -> a -> a
`mappend` (m -> n
cont forall a b. (a -> b) -> a -> b
$! m
p forall a. Semigroup a => a -> a -> a
<> m
prime))
   length :: Shadowed m -> Int
length (Shadowed m
_ m
c) = forall m. Factorial m => m -> Int
length m
c
   reverse :: Shadowed m -> Shadowed m
reverse (Shadowed m
p m
c) = forall m. m -> m -> Shadowed m
Shadowed m
p (forall m. Factorial m => m -> m
Factorial.reverse m
c)
   {-# INLINE primePrefix #-}
   {-# INLINE foldl #-}
   {-# INLINE foldl' #-}
   {-# INLINE foldr #-}
   {-# INLINE foldMap #-}

instance (StableFactorial m, FactorialMonoid m) => FactorialMonoid (Shadowed m) where
   splitPrimePrefix :: Shadowed m -> Maybe (Shadowed m, Shadowed m)
splitPrimePrefix (Shadowed m
p m
c) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (m, m) -> (Shadowed m, Shadowed m)
rewrap (forall m. FactorialMonoid m => m -> Maybe (m, m)
splitPrimePrefix m
c)
      where rewrap :: (m, m) -> (Shadowed m, Shadowed m)
rewrap (m
cp, m
cs) = (forall m. m -> m -> Shadowed m
Shadowed m
p m
cp, forall m. m -> m -> Shadowed m
Shadowed (m
p forall a. Semigroup a => a -> a -> a
<> m
cp) m
cs)
   splitPrimeSuffix :: Shadowed m -> Maybe (Shadowed m, Shadowed m)
splitPrimeSuffix (Shadowed m
p m
c) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (m, m) -> (Shadowed m, Shadowed m)
rewrap (forall m. FactorialMonoid m => m -> Maybe (m, m)
splitPrimeSuffix m
c)
      where rewrap :: (m, m) -> (Shadowed m, Shadowed m)
rewrap (m
cp, m
cs) = (forall m. m -> m -> Shadowed m
Shadowed m
p m
cp, forall m. m -> m -> Shadowed m
Shadowed (m
p forall a. Semigroup a => a -> a -> a
<> m
cp) m
cs)
   spanMaybe :: forall s.
s
-> (s -> Shadowed m -> Maybe s)
-> Shadowed m
-> (Shadowed m, Shadowed m, s)
spanMaybe s
s0 s -> Shadowed m -> Maybe s
f (Shadowed m
p0 m
c) = forall {m} {c}. (m, m, (c, m)) -> (Shadowed m, Shadowed m, c)
rewrap forall a b. (a -> b) -> a -> b
$ forall m s.
FactorialMonoid m =>
s -> (s -> m -> Maybe s) -> m -> (m, m, s)
Factorial.spanMaybe (s
s0, m
p0) (s, m) -> m -> Maybe (s, m)
f' m
c
      where f' :: (s, m) -> m -> Maybe (s, m)
f' (s
s, m
p) m
prime = do s
s' <- s -> Shadowed m -> Maybe s
f s
s (forall m. m -> m -> Shadowed m
Shadowed m
p m
prime)
                                 let p' :: m
p' = m
p forall a. Semigroup a => a -> a -> a
<> m
prime
                                 forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! seq :: forall a b. a -> b -> b
seq m
p' (s
s', m
p')
            rewrap :: (m, m, (c, m)) -> (Shadowed m, Shadowed m, c)
rewrap (m
cp, m
cs, (c
s, m
p)) = (forall m. m -> m -> Shadowed m
Shadowed m
p0 m
cp, forall m. m -> m -> Shadowed m
Shadowed m
p m
cs, c
s)
   spanMaybe' :: forall s.
s
-> (s -> Shadowed m -> Maybe s)
-> Shadowed m
-> (Shadowed m, Shadowed m, s)
spanMaybe' s
s0 s -> Shadowed m -> Maybe s
f (Shadowed m
p0 m
c) = forall {m} {c}. (m, m, (c, m)) -> (Shadowed m, Shadowed m, c)
rewrap forall a b. (a -> b) -> a -> b
$! forall m s.
FactorialMonoid m =>
s -> (s -> m -> Maybe s) -> m -> (m, m, s)
Factorial.spanMaybe' (s
s0, m
p0) (s, m) -> m -> Maybe (s, m)
f' m
c
      where f' :: (s, m) -> m -> Maybe (s, m)
f' (s
s, m
p) m
prime = do s
s' <- s -> Shadowed m -> Maybe s
f s
s (forall m. m -> m -> Shadowed m
Shadowed m
p m
prime)
                                 let p' :: m
p' = m
p forall a. Semigroup a => a -> a -> a
<> m
prime
                                 forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! s
s' seq :: forall a b. a -> b -> b
`seq` m
p' seq :: forall a b. a -> b -> b
`seq` (s
s', m
p')
            rewrap :: (m, m, (c, m)) -> (Shadowed m, Shadowed m, c)
rewrap (m
cp, m
cs, (c
s, m
p)) = (forall m. m -> m -> Shadowed m
Shadowed m
p0 m
cp, forall m. m -> m -> Shadowed m
Shadowed m
p m
cs, c
s)
   span :: (Shadowed m -> Bool) -> Shadowed m -> (Shadowed m, Shadowed m)
span Shadowed m -> Bool
f (Shadowed m
p0 m
c) = forall {m}. (m, m, m) -> (Shadowed m, Shadowed m)
rewrap forall a b. (a -> b) -> a -> b
$ forall m s.
FactorialMonoid m =>
s -> (s -> m -> Maybe s) -> m -> (m, m, s)
Factorial.spanMaybe' m
p0 m -> m -> Maybe m
f' m
c
      where f' :: m -> m -> Maybe m
f' m
p m
prime = if Shadowed m -> Bool
f (forall m. m -> m -> Shadowed m
Shadowed m
p m
prime)
                         then forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! m
p forall a. Semigroup a => a -> a -> a
<> m
prime
                         else forall a. Maybe a
Nothing
            rewrap :: (m, m, m) -> (Shadowed m, Shadowed m)
rewrap (m
cp, m
cs, m
p) = (forall m. m -> m -> Shadowed m
Shadowed m
p0 m
cp, forall m. m -> m -> Shadowed m
Shadowed m
p m
cs)
   splitAt :: Int -> Shadowed m -> (Shadowed m, Shadowed m)
splitAt Int
n (Shadowed m
p m
c) = (forall m. m -> m -> Shadowed m
Shadowed m
p m
cp, forall m. m -> m -> Shadowed m
Shadowed (m
p forall a. Semigroup a => a -> a -> a
<> m
cp) m
cs)
      where (m
cp, m
cs) = forall m. FactorialMonoid m => Int -> m -> (m, m)
splitAt Int
n m
c
   take :: Int -> Shadowed m -> Shadowed m
take Int
n (Shadowed m
p m
c) = forall m. m -> m -> Shadowed m
Shadowed m
p (forall m. FactorialMonoid m => Int -> m -> m
Factorial.take Int
n m
c)
   {-# INLINE splitPrimePrefix #-}
   {-# INLINE splitPrimeSuffix #-}
   {-# INLINE span #-}
   {-# INLINE splitAt #-}
   {-# INLINE take #-}

instance (StableFactorial m, FactorialMonoid m) => StableFactorial (Shadowed m)

instance (Monoid m, IsString m) => IsString (Shadowed m) where
   fromString :: String -> Shadowed m
fromString = forall m. Monoid m => m -> Shadowed m
shadowed forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
fromString

instance (Eq m, StableFactorial m, TextualMonoid m) => TextualMonoid (Shadowed m) where
   splitCharacterPrefix :: Shadowed m -> Maybe (Char, Shadowed m)
splitCharacterPrefix (Shadowed m
p m
t) = (forall m. m -> m -> Shadowed m
Shadowed m
p forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall t. TextualMonoid t => t -> Maybe (Char, t)
Textual.splitCharacterPrefix m
t

   fromText :: Text -> Shadowed m
fromText = forall m. Monoid m => m -> Shadowed m
shadowed forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. TextualMonoid t => Text -> t
fromText
   singleton :: Char -> Shadowed m
singleton = forall m. Monoid m => m -> Shadowed m
shadowed forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. TextualMonoid t => Char -> t
singleton

   characterPrefix :: Shadowed m -> Maybe Char
characterPrefix = forall t. TextualMonoid t => t -> Maybe Char
characterPrefix forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. Shadowed m -> m
content

   map :: (Char -> Char) -> Shadowed m -> Shadowed m
map Char -> Char
f (Shadowed m
p m
c) = forall m. m -> m -> Shadowed m
Shadowed m
p (forall t. TextualMonoid t => (Char -> Char) -> t -> t
map Char -> Char
f m
c)
   concatMap :: (Char -> Shadowed m) -> Shadowed m -> Shadowed m
concatMap Char -> Shadowed m
f (Shadowed m
p m
c) = forall m. m -> m -> Shadowed m
Shadowed m
p (forall t. TextualMonoid t => (Char -> t) -> t -> t
concatMap (forall m. Shadowed m -> m
content forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Shadowed m
f) m
c)
   all :: (Char -> Bool) -> Shadowed m -> Bool
all Char -> Bool
p = forall t. TextualMonoid t => (Char -> Bool) -> t -> Bool
all Char -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. Shadowed m -> m
content
   any :: (Char -> Bool) -> Shadowed m -> Bool
any Char -> Bool
p = forall t. TextualMonoid t => (Char -> Bool) -> t -> Bool
any Char -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. Shadowed m -> m
content

   foldl :: forall a.
(a -> Shadowed m -> a) -> (a -> Char -> a) -> a -> Shadowed m -> a
foldl a -> Shadowed m -> a
ft a -> Char -> a
fc a
a0 (Shadowed m
p0 m
c0) = forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall t a.
TextualMonoid t =>
(a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
Textual.foldl (a, m) -> m -> (a, m)
ft' forall {b}. TextualMonoid b => (a, b) -> Char -> (a, b)
fc' (a
a0, m
p0) m
c0
      where ft' :: (a, m) -> m -> (a, m)
ft' (a
a, m
p) m
c = (a -> Shadowed m -> a
ft a
a (forall m. m -> m -> Shadowed m
Shadowed m
p m
c), m
p forall a. Semigroup a => a -> a -> a
<> m
c)
            fc' :: (a, b) -> Char -> (a, b)
fc' (a
a, b
p) Char
c = (a -> Char -> a
fc a
a Char
c, b
p forall a. Semigroup a => a -> a -> a
<> forall t. TextualMonoid t => Char -> t
Textual.singleton Char
c)
   foldl' :: forall a.
(a -> Shadowed m -> a) -> (a -> Char -> a) -> a -> Shadowed m -> a
foldl' a -> Shadowed m -> a
ft a -> Char -> a
fc a
a0 (Shadowed m
p0 m
c0) = forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall t a.
TextualMonoid t =>
(a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
Textual.foldl' (a, m) -> m -> (a, m)
ft' forall {a}. TextualMonoid a => (a, a) -> Char -> (a, a)
fc' (a
a0, m
p0) m
c0
      where ft' :: (a, m) -> m -> (a, m)
ft' (a
a, m
p) m
c = ((,) forall a b. (a -> b) -> a -> b
$! a -> Shadowed m -> a
ft a
a (forall m. m -> m -> Shadowed m
Shadowed m
p m
c)) forall a b. (a -> b) -> a -> b
$! m
p forall a. Semigroup a => a -> a -> a
<> m
c
            fc' :: (a, a) -> Char -> (a, a)
fc' (a
a, a
p) Char
c = ((,) forall a b. (a -> b) -> a -> b
$! a -> Char -> a
fc a
a Char
c) forall a b. (a -> b) -> a -> b
$! a
p forall a. Semigroup a => a -> a -> a
<> forall t. TextualMonoid t => Char -> t
Textual.singleton Char
c
   foldr :: forall a.
(Shadowed m -> a -> a) -> (Char -> a -> a) -> a -> Shadowed m -> a
foldr Shadowed m -> a -> a
ft Char -> a -> a
fc a
a0 (Shadowed m
p0 m
c0) = forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ forall t a.
TextualMonoid t =>
(t -> a -> a) -> (Char -> a -> a) -> a -> t -> a
Textual.foldr m -> (m, a) -> (m, a)
ft' forall {a}. TextualMonoid a => Char -> (a, a) -> (a, a)
fc' (m
p0, a
a0) m
c0
      where ft' :: m -> (m, a) -> (m, a)
ft' m
c (m
p, a
a) = ((,) forall a b. (a -> b) -> a -> b
$! m
p forall a. Semigroup a => a -> a -> a
<> m
c) forall a b. (a -> b) -> a -> b
$! Shadowed m -> a -> a
ft (forall m. m -> m -> Shadowed m
Shadowed m
p m
c) a
a
            fc' :: Char -> (a, a) -> (a, a)
fc' Char
c (a
p, a
a) = ((,) forall a b. (a -> b) -> a -> b
$! a
p forall a. Semigroup a => a -> a -> a
<> forall t. TextualMonoid t => Char -> t
Textual.singleton Char
c) forall a b. (a -> b) -> a -> b
$! Char -> a -> a
fc Char
c a
a

   scanl :: (Char -> Char -> Char) -> Char -> Shadowed m -> Shadowed m
scanl Char -> Char -> Char
f Char
ch (Shadowed m
p m
c) = forall m. m -> m -> Shadowed m
Shadowed m
p (forall t.
TextualMonoid t =>
(Char -> Char -> Char) -> Char -> t -> t
Textual.scanl Char -> Char -> Char
f Char
ch m
c)
   scanl1 :: (Char -> Char -> Char) -> Shadowed m -> Shadowed m
scanl1 Char -> Char -> Char
f (Shadowed m
p m
c) = forall m. m -> m -> Shadowed m
Shadowed m
p (forall t. TextualMonoid t => (Char -> Char -> Char) -> t -> t
Textual.scanl1 Char -> Char -> Char
f m
c)
   scanr :: (Char -> Char -> Char) -> Char -> Shadowed m -> Shadowed m
scanr Char -> Char -> Char
f Char
ch (Shadowed m
p m
c) = forall m. m -> m -> Shadowed m
Shadowed m
p (forall t.
TextualMonoid t =>
(Char -> Char -> Char) -> Char -> t -> t
Textual.scanr Char -> Char -> Char
f Char
ch m
c)
   scanr1 :: (Char -> Char -> Char) -> Shadowed m -> Shadowed m
scanr1 Char -> Char -> Char
f (Shadowed m
p m
c) = forall m. m -> m -> Shadowed m
Shadowed m
p (forall t. TextualMonoid t => (Char -> Char -> Char) -> t -> t
Textual.scanr1 Char -> Char -> Char
f m
c)
   mapAccumL :: forall a.
(a -> Char -> (a, Char)) -> a -> Shadowed m -> (a, Shadowed m)
mapAccumL a -> Char -> (a, Char)
f a
a0 (Shadowed m
p m
c) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall m. m -> m -> Shadowed m
Shadowed m
p) (forall t a.
TextualMonoid t =>
(a -> Char -> (a, Char)) -> a -> t -> (a, t)
Textual.mapAccumL a -> Char -> (a, Char)
f a
a0 m
c)
   mapAccumR :: forall a.
(a -> Char -> (a, Char)) -> a -> Shadowed m -> (a, Shadowed m)
mapAccumR a -> Char -> (a, Char)
f a
a0 (Shadowed m
p m
c) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall m. m -> m -> Shadowed m
Shadowed m
p) (forall t a.
TextualMonoid t =>
(a -> Char -> (a, Char)) -> a -> t -> (a, t)
Textual.mapAccumR a -> Char -> (a, Char)
f a
a0 m
c)

   spanMaybe :: forall s.
s
-> (s -> Shadowed m -> Maybe s)
-> (s -> Char -> Maybe s)
-> Shadowed m
-> (Shadowed m, Shadowed m, s)
spanMaybe s
s0 s -> Shadowed m -> Maybe s
ft s -> Char -> Maybe s
fc (Shadowed m
p0 m
t) = forall {m} {c}. (m, m, (c, m)) -> (Shadowed m, Shadowed m, c)
rewrap forall a b. (a -> b) -> a -> b
$ forall t s.
TextualMonoid t =>
s
-> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe (s
s0, m
p0) (s, m) -> m -> Maybe (s, m)
ft' forall {b}. TextualMonoid b => (s, b) -> Char -> Maybe (s, b)
fc' m
t
      where ft' :: (s, m) -> m -> Maybe (s, m)
ft' (s
s, m
p) m
prime = do s
s' <- s -> Shadowed m -> Maybe s
ft s
s (forall m. m -> m -> Shadowed m
Shadowed m
p m
prime)
                                  let p' :: m
p' = m
p forall a. Semigroup a => a -> a -> a
<> m
prime
                                  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! seq :: forall a b. a -> b -> b
seq m
p' (s
s', m
p')
            fc' :: (s, b) -> Char -> Maybe (s, b)
fc' (s
s, b
p) Char
c = do s
s' <- s -> Char -> Maybe s
fc s
s Char
c
                              let p' :: b
p' = b
p forall a. Semigroup a => a -> a -> a
<> forall t. TextualMonoid t => Char -> t
Textual.singleton Char
c
                              forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! seq :: forall a b. a -> b -> b
seq b
p' (s
s', b
p')
            rewrap :: (m, m, (c, m)) -> (Shadowed m, Shadowed m, c)
rewrap (m
tp, m
ts, (c
s, m
p)) = (forall m. m -> m -> Shadowed m
Shadowed m
p0 m
tp, forall m. m -> m -> Shadowed m
Shadowed m
p m
ts, c
s)
   spanMaybe' :: forall s.
s
-> (s -> Shadowed m -> Maybe s)
-> (s -> Char -> Maybe s)
-> Shadowed m
-> (Shadowed m, Shadowed m, s)
spanMaybe' s
s0 s -> Shadowed m -> Maybe s
ft s -> Char -> Maybe s
fc (Shadowed m
p0 m
t) = forall {m} {c}. (m, m, (c, m)) -> (Shadowed m, Shadowed m, c)
rewrap forall a b. (a -> b) -> a -> b
$! forall t s.
TextualMonoid t =>
s
-> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe' (s
s0, m
p0) (s, m) -> m -> Maybe (s, m)
ft' forall {b}. TextualMonoid b => (s, b) -> Char -> Maybe (s, b)
fc' m
t
      where ft' :: (s, m) -> m -> Maybe (s, m)
ft' (s
s, m
p) m
prime = do s
s' <- s -> Shadowed m -> Maybe s
ft s
s (forall m. m -> m -> Shadowed m
Shadowed m
p m
prime)
                                  let p' :: m
p' = m
p forall a. Semigroup a => a -> a -> a
<> m
prime
                                  forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! s
s' seq :: forall a b. a -> b -> b
`seq` m
p' seq :: forall a b. a -> b -> b
`seq` (s
s', m
p')
            fc' :: (s, b) -> Char -> Maybe (s, b)
fc' (s
s, b
p) Char
c = do s
s' <- s -> Char -> Maybe s
fc s
s Char
c
                              let p' :: b
p' = b
p forall a. Semigroup a => a -> a -> a
<> forall t. TextualMonoid t => Char -> t
Textual.singleton Char
c
                              forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! s
s' seq :: forall a b. a -> b -> b
`seq` b
p' seq :: forall a b. a -> b -> b
`seq` (s
s', b
p')
            rewrap :: (m, m, (c, m)) -> (Shadowed m, Shadowed m, c)
rewrap (m
tp, m
ts, (c
s, m
p)) = (forall m. m -> m -> Shadowed m
Shadowed m
p0 m
tp, forall m. m -> m -> Shadowed m
Shadowed m
p m
ts, c
s)
   span :: (Shadowed m -> Bool)
-> (Char -> Bool) -> Shadowed m -> (Shadowed m, Shadowed m)
span Shadowed m -> Bool
ft Char -> Bool
fc (Shadowed m
p0 m
t) = forall {m}. (m, m, m) -> (Shadowed m, Shadowed m)
rewrap forall a b. (a -> b) -> a -> b
$ forall t s.
TextualMonoid t =>
s
-> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe' m
p0 m -> m -> Maybe m
ft' forall {a}. TextualMonoid a => a -> Char -> Maybe a
fc' m
t
      where ft' :: m -> m -> Maybe m
ft' m
p m
prime = if Shadowed m -> Bool
ft (forall m. m -> m -> Shadowed m
Shadowed m
p m
prime)
                          then forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! m
p forall a. Semigroup a => a -> a -> a
<> m
prime
                          else forall a. Maybe a
Nothing
            fc' :: a -> Char -> Maybe a
fc' a
p Char
c = if Char -> Bool
fc Char
c
                      then forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! a
p forall a. Semigroup a => a -> a -> a
<> forall t. TextualMonoid t => Char -> t
Textual.singleton Char
c
                      else forall a. Maybe a
Nothing
            rewrap :: (m, m, m) -> (Shadowed m, Shadowed m)
rewrap (m
tp, m
ts, m
p) = (forall m. m -> m -> Shadowed m
Shadowed m
p0 m
tp, forall m. m -> m -> Shadowed m
Shadowed m
p m
ts)

   split :: (Char -> Bool) -> Shadowed m -> [Shadowed m]
split Char -> Bool
f (Shadowed m
p0 m
c0) = forall {t}. Semigroup t => t -> [t] -> [Shadowed t]
rewrap m
p0 (forall t. TextualMonoid t => (Char -> Bool) -> t -> [t]
Textual.split Char -> Bool
f m
c0)
      where rewrap :: t -> [t] -> [Shadowed t]
rewrap t
_ [] = []
            rewrap t
p (t
c:[t]
rest) = forall m. m -> m -> Shadowed m
Shadowed t
p t
c forall a. a -> [a] -> [a]
: t -> [t] -> [Shadowed t]
rewrap (t
p forall a. Semigroup a => a -> a -> a
<> t
c) [t]
rest
   find :: (Char -> Bool) -> Shadowed m -> Maybe Char
find Char -> Bool
p = forall t. TextualMonoid t => (Char -> Bool) -> t -> Maybe Char
find Char -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. Shadowed m -> m
content

   foldl_ :: forall a. (a -> Char -> a) -> a -> Shadowed m -> a
foldl_ a -> Char -> a
fc a
a0 (Shadowed m
_ m
c) = forall t a. TextualMonoid t => (a -> Char -> a) -> a -> t -> a
Textual.foldl_ a -> Char -> a
fc a
a0 m
c
   foldl_' :: forall a. (a -> Char -> a) -> a -> Shadowed m -> a
foldl_' a -> Char -> a
fc a
a0 (Shadowed m
_ m
c) = forall t a. TextualMonoid t => (a -> Char -> a) -> a -> t -> a
Textual.foldl_' a -> Char -> a
fc a
a0 m
c
   foldr_ :: forall a. (Char -> a -> a) -> a -> Shadowed m -> a
foldr_ Char -> a -> a
fc a
a0 (Shadowed m
_ m
c) = forall t a. TextualMonoid t => (Char -> a -> a) -> a -> t -> a
Textual.foldr_ Char -> a -> a
fc a
a0 m
c

   spanMaybe_ :: forall s.
s
-> (s -> Char -> Maybe s)
-> Shadowed m
-> (Shadowed m, Shadowed m, s)
spanMaybe_ s
s0 s -> Char -> Maybe s
fc (Shadowed m
p0 m
t) = forall {m} {c}. (m, m, (c, m)) -> (Shadowed m, Shadowed m, c)
rewrap forall a b. (a -> b) -> a -> b
$ forall t s.
TextualMonoid t =>
s -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe_' (s
s0, m
p0) forall {b}. TextualMonoid b => (s, b) -> Char -> Maybe (s, b)
fc' m
t
      where fc' :: (s, b) -> Char -> Maybe (s, b)
fc' (s
s, b
p) Char
c = do s
s' <- s -> Char -> Maybe s
fc s
s Char
c
                              let p' :: b
p' = b
p forall a. Semigroup a => a -> a -> a
<> forall t. TextualMonoid t => Char -> t
Textual.singleton Char
c
                              forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! seq :: forall a b. a -> b -> b
seq b
p' (s
s', b
p')
            rewrap :: (m, m, (c, m)) -> (Shadowed m, Shadowed m, c)
rewrap (m
tp, m
ts, (c
s, m
p)) = (forall m. m -> m -> Shadowed m
Shadowed m
p0 m
tp, forall m. m -> m -> Shadowed m
Shadowed m
p m
ts, c
s)
   spanMaybe_' :: forall s.
s
-> (s -> Char -> Maybe s)
-> Shadowed m
-> (Shadowed m, Shadowed m, s)
spanMaybe_' s
s0 s -> Char -> Maybe s
fc (Shadowed m
p0 m
t) = forall {m} {c}. (m, m, (c, m)) -> (Shadowed m, Shadowed m, c)
rewrap forall a b. (a -> b) -> a -> b
$! forall t s.
TextualMonoid t =>
s -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe_' (s
s0, m
p0) forall {b}. TextualMonoid b => (s, b) -> Char -> Maybe (s, b)
fc' m
t
      where fc' :: (s, b) -> Char -> Maybe (s, b)
fc' (s
s, b
p) Char
c = do s
s' <- s -> Char -> Maybe s
fc s
s Char
c
                              let p' :: b
p' = b
p forall a. Semigroup a => a -> a -> a
<> forall t. TextualMonoid t => Char -> t
Textual.singleton Char
c
                              forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! s
s' seq :: forall a b. a -> b -> b
`seq` b
p' seq :: forall a b. a -> b -> b
`seq` (s
s', b
p')
            rewrap :: (m, m, (c, m)) -> (Shadowed m, Shadowed m, c)
rewrap (m
tp, m
ts, (c
s, m
p)) = (forall m. m -> m -> Shadowed m
Shadowed m
p0 m
tp, forall m. m -> m -> Shadowed m
Shadowed m
p m
ts, c
s)
   span_ :: Bool -> (Char -> Bool) -> Shadowed m -> (Shadowed m, Shadowed m)
span_ Bool
bt Char -> Bool
fc (Shadowed m
p0 m
t) = (m, m) -> (Shadowed m, Shadowed m)
rewrap forall a b. (a -> b) -> a -> b
$ forall t. TextualMonoid t => Bool -> (Char -> Bool) -> t -> (t, t)
Textual.span_ Bool
bt Char -> Bool
fc m
t
      where rewrap :: (m, m) -> (Shadowed m, Shadowed m)
rewrap (m
tp, m
ts) = (forall m. m -> m -> Shadowed m
Shadowed m
p0 m
tp, forall m. m -> m -> Shadowed m
Shadowed (m
p0 forall a. Semigroup a => a -> a -> a
<> m
tp) m
ts)
   break_ :: Bool -> (Char -> Bool) -> Shadowed m -> (Shadowed m, Shadowed m)
break_ Bool
bt Char -> Bool
fc (Shadowed m
p0 m
t) = (m, m) -> (Shadowed m, Shadowed m)
rewrap forall a b. (a -> b) -> a -> b
$ forall t. TextualMonoid t => Bool -> (Char -> Bool) -> t -> (t, t)
Textual.break_ Bool
bt Char -> Bool
fc m
t
      where rewrap :: (m, m) -> (Shadowed m, Shadowed m)
rewrap (m
tp, m
ts) = (forall m. m -> m -> Shadowed m
Shadowed m
p0 m
tp, forall m. m -> m -> Shadowed m
Shadowed (m
p0 forall a. Semigroup a => a -> a -> a
<> m
tp) m
ts)
   dropWhile_ :: Bool -> (Char -> Bool) -> Shadowed m -> Shadowed m
dropWhile_ Bool
bt Char -> Bool
fc Shadowed m
t = forall a b. (a, b) -> b
snd (forall t. TextualMonoid t => Bool -> (Char -> Bool) -> t -> (t, t)
span_ Bool
bt Char -> Bool
fc Shadowed m
t)
   takeWhile_ :: Bool -> (Char -> Bool) -> Shadowed m -> Shadowed m
takeWhile_ Bool
bt Char -> Bool
fc (Shadowed m
p m
t) = forall m. m -> m -> Shadowed m
Shadowed m
p (forall t. TextualMonoid t => Bool -> (Char -> Bool) -> t -> t
takeWhile_ Bool
bt Char -> Bool
fc m
t)
   toString :: (Shadowed m -> String) -> Shadowed m -> String
toString Shadowed m -> String
ft (Shadowed m
_ m
t) = forall t. TextualMonoid t => (t -> String) -> t -> String
toString (Shadowed m -> String
ft forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. Monoid m => m -> Shadowed m
shadowed) m
t
   toText :: (Shadowed m -> Text) -> Shadowed m -> Text
toText Shadowed m -> Text
ft (Shadowed m
_ m
t) = forall t. TextualMonoid t => (t -> Text) -> t -> Text
toText (Shadowed m -> Text
ft forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. Monoid m => m -> Shadowed m
shadowed) m
t

   {-# INLINE characterPrefix #-}
   {-# INLINE splitCharacterPrefix #-}
   {-# INLINE map #-}
   {-# INLINE concatMap #-}
   {-# INLINE foldl' #-}
   {-# INLINE foldr #-}
   {-# INLINABLE spanMaybe #-}
   {-# INLINABLE spanMaybe' #-}
   {-# INLINABLE span #-}
   {-# INLINE foldl_' #-}
   {-# INLINE foldr_ #-}
   {-# INLINE any #-}
   {-# INLINE all #-}
   {-# INLINABLE spanMaybe_ #-}
   {-# INLINABLE spanMaybe_' #-}
   {-# INLINE span_ #-}
   {-# INLINE break_ #-}
   {-# INLINE dropWhile_ #-}
   {-# INLINE takeWhile_ #-}
   {-# INLINE split #-}
   {-# INLINE find #-}