{-# LANGUAGE Haskell2010, DeriveDataTypeable #-}
module Data.Monoid.Instances.Measured (
Measured, measure, extract
)
where
import Data.Functor
import Data.Data (Data, Typeable)
import qualified Data.List as List
import Data.String (IsString(..))
import Data.Semigroup (Semigroup(..))
import Data.Monoid (Monoid(..))
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.Monoid.Factorial as Factorial
import qualified Data.Monoid.Textual as Textual
import Prelude hiding (all, any, break, filter, foldl, foldl1, foldr, foldr1, map, concatMap,
length, null, reverse, scanl, scanr, scanl1, scanr1, span, splitAt)
data Measured a = Measured{forall a. Measured a -> Int
_measuredLength :: Int, :: a} deriving (Measured a -> DataType
Measured a -> Constr
forall {a}. Data a => Typeable (Measured a)
forall a. Data a => Measured a -> DataType
forall a. Data a => Measured a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> Measured a -> Measured a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Measured a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> Measured a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Measured a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Measured a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Measured a -> m (Measured a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Measured a -> m (Measured a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Measured a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Measured a -> c (Measured a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Measured a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Measured a))
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 (Measured a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Measured a -> c (Measured a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Measured a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Measured a -> m (Measured a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Measured a -> m (Measured a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Measured a -> m (Measured a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Measured a -> m (Measured a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Measured a -> m (Measured a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Measured a -> m (Measured a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Measured a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Measured a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Measured a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> Measured a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Measured a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Measured a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Measured a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Measured a -> r
gmapT :: (forall b. Data b => b -> b) -> Measured a -> Measured a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> Measured a -> Measured a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Measured a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Measured a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Measured a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Measured a))
dataTypeOf :: Measured a -> DataType
$cdataTypeOf :: forall a. Data a => Measured a -> DataType
toConstr :: Measured a -> Constr
$ctoConstr :: forall a. Data a => Measured a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Measured a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Measured a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Measured a -> c (Measured a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Measured a -> c (Measured a)
Data, Measured a -> Measured a -> Bool
forall a. Eq a => Measured a -> Measured a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Measured a -> Measured a -> Bool
$c/= :: forall a. Eq a => Measured a -> Measured a -> Bool
== :: Measured a -> Measured a -> Bool
$c== :: forall a. Eq a => Measured a -> Measured a -> Bool
Eq, Int -> Measured a -> ShowS
forall a. Show a => Int -> Measured a -> ShowS
forall a. Show a => [Measured a] -> ShowS
forall a. Show a => Measured a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Measured a] -> ShowS
$cshowList :: forall a. Show a => [Measured a] -> ShowS
show :: Measured a -> String
$cshow :: forall a. Show a => Measured a -> String
showsPrec :: Int -> Measured a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Measured a -> ShowS
Show, Typeable)
measure :: Factorial a => a -> Measured a
measure :: forall a. Factorial a => a -> Measured a
measure a
x = forall a. Int -> a -> Measured a
Measured (forall m. Factorial m => m -> Int
length a
x) a
x
instance Ord a => Ord (Measured a) where
compare :: Measured a -> Measured a -> Ordering
compare (Measured Int
_ a
x) (Measured Int
_ a
y) = forall a. Ord a => a -> a -> Ordering
compare a
x a
y
instance StableFactorial a => Semigroup (Measured a) where
Measured Int
m a
a <> :: Measured a -> Measured a -> Measured a
<> Measured Int
n a
b = forall a. Int -> a -> Measured a
Measured (Int
m forall a. Num a => a -> a -> a
+ Int
n) (a
a forall a. Semigroup a => a -> a -> a
<> a
b)
instance (StableFactorial a, Monoid a) => Monoid (Measured a) where
mempty :: Measured a
mempty = forall a. Int -> a -> Measured a
Measured Int
0 forall a. Monoid a => a
mempty
mappend :: Measured a -> Measured a -> Measured a
mappend = forall a. Semigroup a => a -> a -> a
(<>)
instance (StableFactorial a, Monoid a) => MonoidNull (Measured a) where
null :: Measured a -> Bool
null (Measured Int
n a
_) = Int
n forall a. Eq a => a -> a -> Bool
== Int
0
instance (StableFactorial a, Monoid a) => PositiveMonoid (Measured a)
instance (LeftReductive a, StableFactorial a) => LeftReductive (Measured a) where
stripPrefix :: Measured a -> Measured a -> Maybe (Measured a)
stripPrefix (Measured Int
m a
x) (Measured Int
n a
y) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. Int -> a -> Measured a
Measured (Int
n forall a. Num a => a -> a -> a
- Int
m)) (forall m. LeftReductive m => m -> m -> Maybe m
stripPrefix a
x a
y)
instance (RightReductive a, StableFactorial a) => RightReductive (Measured a) where
stripSuffix :: Measured a -> Measured a -> Maybe (Measured a)
stripSuffix (Measured Int
m a
x) (Measured Int
n a
y) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. Int -> a -> Measured a
Measured (Int
n forall a. Num a => a -> a -> a
- Int
m)) (forall m. RightReductive m => m -> m -> Maybe m
stripSuffix a
x a
y)
instance (LeftGCDMonoid a, StableFactorial a) => LeftGCDMonoid (Measured a) where
commonPrefix :: Measured a -> Measured a -> Measured a
commonPrefix (Measured Int
_ a
x) (Measured Int
_ a
y) = forall a. Factorial a => a -> Measured a
measure (forall m. LeftGCDMonoid m => m -> m -> m
commonPrefix a
x a
y)
instance (RightGCDMonoid a, StableFactorial a) => RightGCDMonoid (Measured a) where
commonSuffix :: Measured a -> Measured a -> Measured a
commonSuffix (Measured Int
_ a
x) (Measured Int
_ a
y) = forall a. Factorial a => a -> Measured a
measure (forall m. RightGCDMonoid m => m -> m -> m
commonSuffix a
x a
y)
instance (StableFactorial a, MonoidNull a) => Factorial (Measured a) where
factors :: Measured a -> [Measured a]
factors (Measured Int
_ a
x) = forall a b. (a -> b) -> [a] -> [b]
List.map (forall a. Int -> a -> Measured a
Measured Int
1) (forall m. Factorial m => m -> [m]
factors a
x)
primePrefix :: Measured a -> Measured a
primePrefix m :: Measured a
m@(Measured Int
_ a
x) = if forall m. MonoidNull m => m -> Bool
null a
x then Measured a
m else forall a. Int -> a -> Measured a
Measured Int
1 (forall m. Factorial m => m -> m
primePrefix a
x)
primeSuffix :: Measured a -> Measured a
primeSuffix m :: Measured a
m@(Measured Int
_ a
x) = if forall m. MonoidNull m => m -> Bool
null a
x then Measured a
m else forall a. Int -> a -> Measured a
Measured Int
1 (forall m. Factorial m => m -> m
primeSuffix a
x)
foldl :: forall a. (a -> Measured a -> a) -> a -> Measured a -> a
foldl a -> Measured a -> a
f a
a0 (Measured Int
_ a
x) = forall m a. Factorial m => (a -> m -> a) -> a -> m -> a
Factorial.foldl a -> a -> a
g a
a0 a
x
where g :: a -> a -> a
g a
a = a -> Measured a -> a
f a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> a -> Measured a
Measured Int
1
foldl' :: forall a. (a -> Measured a -> a) -> a -> Measured a -> a
foldl' a -> Measured a -> a
f a
a0 (Measured Int
_ a
x) = forall m a. Factorial m => (a -> m -> a) -> a -> m -> a
Factorial.foldl' a -> a -> a
g a
a0 a
x
where g :: a -> a -> a
g a
a = a -> Measured a -> a
f a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> a -> Measured a
Measured Int
1
foldr :: forall a. (Measured a -> a -> a) -> a -> Measured a -> a
foldr Measured a -> a -> a
f a
a0 (Measured Int
_ a
x) = forall m a. Factorial m => (m -> a -> a) -> a -> m -> a
Factorial.foldr a -> a -> a
g a
a0 a
x
where g :: a -> a -> a
g = Measured a -> a -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> a -> Measured a
Measured Int
1
foldMap :: forall n. Monoid n => (Measured a -> n) -> Measured a -> n
foldMap Measured a -> n
f (Measured Int
_ a
x) = forall m n. (Factorial m, Monoid n) => (m -> n) -> m -> n
Factorial.foldMap (Measured a -> n
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> a -> Measured a
Measured Int
1) a
x
length :: Measured a -> Int
length (Measured Int
n a
_) = Int
n
reverse :: Measured a -> Measured a
reverse (Measured Int
n a
x) = forall a. Int -> a -> Measured a
Measured Int
n (forall m. Factorial m => m -> m
reverse a
x)
instance (StableFactorial a, FactorialMonoid a) => FactorialMonoid (Measured a) where
splitPrimePrefix :: Measured a -> Maybe (Measured a, Measured a)
splitPrimePrefix (Measured Int
n a
x) = case forall m. FactorialMonoid m => m -> Maybe (m, m)
splitPrimePrefix a
x
of Maybe (a, a)
Nothing -> forall a. Maybe a
Nothing
Just (a
p, a
s) -> forall a. a -> Maybe a
Just (forall a. Int -> a -> Measured a
Measured Int
1 a
p, forall a. Int -> a -> Measured a
Measured (Int
n forall a. Num a => a -> a -> a
- Int
1) a
s)
splitPrimeSuffix :: Measured a -> Maybe (Measured a, Measured a)
splitPrimeSuffix (Measured Int
n a
x) = case forall m. FactorialMonoid m => m -> Maybe (m, m)
splitPrimeSuffix a
x
of Maybe (a, a)
Nothing -> forall a. Maybe a
Nothing
Just (a
p, a
s) -> forall a. a -> Maybe a
Just (forall a. Int -> a -> Measured a
Measured (Int
n forall a. Num a => a -> a -> a
- Int
1) a
p, forall a. Int -> a -> Measured a
Measured Int
1 a
s)
span :: (Measured a -> Bool) -> Measured a -> (Measured a, Measured a)
span Measured a -> Bool
p (Measured Int
n a
x) = (Measured a
xp', Measured a
xs')
where (a
xp, a
xs) = forall m. FactorialMonoid m => (m -> Bool) -> m -> (m, m)
Factorial.span (Measured a -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> a -> Measured a
Measured Int
1) a
x
xp' :: Measured a
xp' = forall a. Factorial a => a -> Measured a
measure a
xp
xs' :: Measured a
xs' = forall a. Int -> a -> Measured a
Measured (Int
n forall a. Num a => a -> a -> a
- forall m. Factorial m => m -> Int
length Measured a
xp') a
xs
split :: (Measured a -> Bool) -> Measured a -> [Measured a]
split Measured a -> Bool
p (Measured Int
_ a
x) = forall a. Factorial a => a -> Measured a
measure forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall m. FactorialMonoid m => (m -> Bool) -> m -> [m]
Factorial.split (Measured a -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> a -> Measured a
Measured Int
1) a
x
splitAt :: Int -> Measured a -> (Measured a, Measured a)
splitAt Int
m (Measured Int
n a
x) | Int
m forall a. Ord a => a -> a -> Bool
<= Int
0 = (forall a. Monoid a => a
mempty, forall a. Int -> a -> Measured a
Measured Int
n a
x)
| Int
m forall a. Ord a => a -> a -> Bool
>= Int
n = (forall a. Int -> a -> Measured a
Measured Int
n a
x, forall a. Monoid a => a
mempty)
| Bool
otherwise = (forall a. Int -> a -> Measured a
Measured Int
m a
xp, forall a. Int -> a -> Measured a
Measured (Int
n forall a. Num a => a -> a -> a
- Int
m) a
xs)
where (a
xp, a
xs) = forall m. FactorialMonoid m => Int -> m -> (m, m)
splitAt Int
m a
x
instance (StableFactorial a, MonoidNull a) => StableFactorial (Measured a)
instance (FactorialMonoid a, IsString a) => IsString (Measured a) where
fromString :: String -> Measured a
fromString = forall a. Factorial a => a -> Measured a
measure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
fromString
instance (Eq a, StableFactorial a, TextualMonoid a) => TextualMonoid (Measured a) where
fromText :: Text -> Measured a
fromText = forall a. Factorial a => a -> Measured a
measure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. TextualMonoid t => Text -> t
fromText
singleton :: Char -> Measured a
singleton = forall a. Int -> a -> Measured a
Measured Int
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. TextualMonoid t => Char -> t
singleton
splitCharacterPrefix :: Measured a -> Maybe (Char, Measured a)
splitCharacterPrefix (Measured Int
n a
x) = (forall a. Int -> a -> Measured a
Measured (Int
n forall a. Num a => a -> a -> a
- Int
1) 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)
splitCharacterPrefix a
x
characterPrefix :: Measured a -> Maybe Char
characterPrefix (Measured Int
_ a
x) = forall t. TextualMonoid t => t -> Maybe Char
characterPrefix a
x
map :: (Char -> Char) -> Measured a -> Measured a
map Char -> Char
f (Measured Int
n a
x) = forall a. Int -> a -> Measured a
Measured Int
n (forall t. TextualMonoid t => (Char -> Char) -> t -> t
map Char -> Char
f a
x)
any :: (Char -> Bool) -> Measured a -> Bool
any Char -> Bool
p (Measured Int
_ a
x) = forall t. TextualMonoid t => (Char -> Bool) -> t -> Bool
any Char -> Bool
p a
x
all :: (Char -> Bool) -> Measured a -> Bool
all Char -> Bool
p (Measured Int
_ a
x) = forall t. TextualMonoid t => (Char -> Bool) -> t -> Bool
all Char -> Bool
p a
x
foldl :: forall a.
(a -> Measured a -> a) -> (a -> Char -> a) -> a -> Measured a -> a
foldl a -> Measured a -> a
ft a -> Char -> a
fc a
a0 (Measured Int
_ a
x) = forall t a.
TextualMonoid t =>
(a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
Textual.foldl (\a
a-> a -> Measured a -> a
ft a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> a -> Measured a
Measured Int
1) a -> Char -> a
fc a
a0 a
x
foldl' :: forall a.
(a -> Measured a -> a) -> (a -> Char -> a) -> a -> Measured a -> a
foldl' a -> Measured a -> a
ft a -> Char -> a
fc a
a0 (Measured Int
_ a
x) = forall t a.
TextualMonoid t =>
(a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
Textual.foldl' (\a
a-> a -> Measured a -> a
ft a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> a -> Measured a
Measured Int
1) a -> Char -> a
fc a
a0 a
x
foldr :: forall a.
(Measured a -> a -> a) -> (Char -> a -> a) -> a -> Measured a -> a
foldr Measured a -> a -> a
ft Char -> a -> a
fc a
a0 (Measured Int
_ a
x) = forall t a.
TextualMonoid t =>
(t -> a -> a) -> (Char -> a -> a) -> a -> t -> a
Textual.foldr (Measured a -> a -> a
ft forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> a -> Measured a
Measured Int
1) Char -> a -> a
fc a
a0 a
x
toString :: (Measured a -> String) -> Measured a -> String
toString Measured a -> String
ft (Measured Int
_ a
x) = forall t. TextualMonoid t => (t -> String) -> t -> String
toString (Measured a -> String
ft forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> a -> Measured a
Measured Int
1) a
x
toText :: (Measured a -> Text) -> Measured a -> Text
toText Measured a -> Text
ft (Measured Int
_ a
x) = forall t. TextualMonoid t => (t -> Text) -> t -> Text
toText (Measured a -> Text
ft forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> a -> Measured a
Measured Int
1) a
x
span :: (Measured a -> Bool)
-> (Char -> Bool) -> Measured a -> (Measured a, Measured a)
span Measured a -> Bool
pt Char -> Bool
pc (Measured Int
n a
x) = (Measured a
xp', Measured a
xs')
where (a
xp, a
xs) = forall t.
TextualMonoid t =>
(t -> Bool) -> (Char -> Bool) -> t -> (t, t)
Textual.span (Measured a -> Bool
pt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> a -> Measured a
Measured Int
1) Char -> Bool
pc a
x
xp' :: Measured a
xp' = forall a. Factorial a => a -> Measured a
measure a
xp
xs' :: Measured a
xs' = forall a. Int -> a -> Measured a
Measured (Int
n forall a. Num a => a -> a -> a
- forall m. Factorial m => m -> Int
length Measured a
xp') a
xs
break :: (Measured a -> Bool)
-> (Char -> Bool) -> Measured a -> (Measured a, Measured a)
break Measured a -> Bool
pt Char -> Bool
pc = forall t.
TextualMonoid t =>
(t -> Bool) -> (Char -> Bool) -> t -> (t, t)
Textual.span (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Measured a -> Bool
pt) (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
pc)
find :: (Char -> Bool) -> Measured a -> Maybe Char
find Char -> Bool
p (Measured Int
_ a
x) = forall t. TextualMonoid t => (Char -> Bool) -> t -> Maybe Char
find Char -> Bool
p a
x