{-# OPTIONS_GHC -Wno-orphans #-}
module Data.Geometry.RangeTree.Measure where
import Data.Measured.Class
import Data.Functor.Product(Product(..))
import Data.Functor.Classes
class LabeledMeasure v where
labeledMeasure :: [a] -> v a
newtype Report p = Report { Report p -> [p]
reportList :: [p] }
deriving (Int -> Report p -> ShowS
[Report p] -> ShowS
Report p -> String
(Int -> Report p -> ShowS)
-> (Report p -> String) -> ([Report p] -> ShowS) -> Show (Report p)
forall p. Show p => Int -> Report p -> ShowS
forall p. Show p => [Report p] -> ShowS
forall p. Show p => Report p -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Report p] -> ShowS
$cshowList :: forall p. Show p => [Report p] -> ShowS
show :: Report p -> String
$cshow :: forall p. Show p => Report p -> String
showsPrec :: Int -> Report p -> ShowS
$cshowsPrec :: forall p. Show p => Int -> Report p -> ShowS
Show,Report p -> Report p -> Bool
(Report p -> Report p -> Bool)
-> (Report p -> Report p -> Bool) -> Eq (Report p)
forall p. Eq p => Report p -> Report p -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Report p -> Report p -> Bool
$c/= :: forall p. Eq p => Report p -> Report p -> Bool
== :: Report p -> Report p -> Bool
$c== :: forall p. Eq p => Report p -> Report p -> Bool
Eq,Eq (Report p)
Eq (Report p)
-> (Report p -> Report p -> Ordering)
-> (Report p -> Report p -> Bool)
-> (Report p -> Report p -> Bool)
-> (Report p -> Report p -> Bool)
-> (Report p -> Report p -> Bool)
-> (Report p -> Report p -> Report p)
-> (Report p -> Report p -> Report p)
-> Ord (Report p)
Report p -> Report p -> Bool
Report p -> Report p -> Ordering
Report p -> Report p -> Report p
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall p. Ord p => Eq (Report p)
forall p. Ord p => Report p -> Report p -> Bool
forall p. Ord p => Report p -> Report p -> Ordering
forall p. Ord p => Report p -> Report p -> Report p
min :: Report p -> Report p -> Report p
$cmin :: forall p. Ord p => Report p -> Report p -> Report p
max :: Report p -> Report p -> Report p
$cmax :: forall p. Ord p => Report p -> Report p -> Report p
>= :: Report p -> Report p -> Bool
$c>= :: forall p. Ord p => Report p -> Report p -> Bool
> :: Report p -> Report p -> Bool
$c> :: forall p. Ord p => Report p -> Report p -> Bool
<= :: Report p -> Report p -> Bool
$c<= :: forall p. Ord p => Report p -> Report p -> Bool
< :: Report p -> Report p -> Bool
$c< :: forall p. Ord p => Report p -> Report p -> Bool
compare :: Report p -> Report p -> Ordering
$ccompare :: forall p. Ord p => Report p -> Report p -> Ordering
$cp1Ord :: forall p. Ord p => Eq (Report p)
Ord,a -> Report b -> Report a
(a -> b) -> Report a -> Report b
(forall a b. (a -> b) -> Report a -> Report b)
-> (forall a b. a -> Report b -> Report a) -> Functor Report
forall a b. a -> Report b -> Report a
forall a b. (a -> b) -> Report a -> Report b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Report b -> Report a
$c<$ :: forall a b. a -> Report b -> Report a
fmap :: (a -> b) -> Report a -> Report b
$cfmap :: forall a b. (a -> b) -> Report a -> Report b
Functor,a -> Report a -> Bool
Report m -> m
Report a -> [a]
Report a -> Bool
Report a -> Int
Report a -> a
Report a -> a
Report a -> a
Report a -> a
(a -> m) -> Report a -> m
(a -> m) -> Report a -> m
(a -> b -> b) -> b -> Report a -> b
(a -> b -> b) -> b -> Report a -> b
(b -> a -> b) -> b -> Report a -> b
(b -> a -> b) -> b -> Report a -> b
(a -> a -> a) -> Report a -> a
(a -> a -> a) -> Report a -> a
(forall m. Monoid m => Report m -> m)
-> (forall m a. Monoid m => (a -> m) -> Report a -> m)
-> (forall m a. Monoid m => (a -> m) -> Report a -> m)
-> (forall a b. (a -> b -> b) -> b -> Report a -> b)
-> (forall a b. (a -> b -> b) -> b -> Report a -> b)
-> (forall b a. (b -> a -> b) -> b -> Report a -> b)
-> (forall b a. (b -> a -> b) -> b -> Report a -> b)
-> (forall a. (a -> a -> a) -> Report a -> a)
-> (forall a. (a -> a -> a) -> Report a -> a)
-> (forall a. Report a -> [a])
-> (forall a. Report a -> Bool)
-> (forall a. Report a -> Int)
-> (forall a. Eq a => a -> Report a -> Bool)
-> (forall a. Ord a => Report a -> a)
-> (forall a. Ord a => Report a -> a)
-> (forall a. Num a => Report a -> a)
-> (forall a. Num a => Report a -> a)
-> Foldable Report
forall a. Eq a => a -> Report a -> Bool
forall a. Num a => Report a -> a
forall a. Ord a => Report a -> a
forall m. Monoid m => Report m -> m
forall a. Report a -> Bool
forall a. Report a -> Int
forall a. Report a -> [a]
forall a. (a -> a -> a) -> Report a -> a
forall m a. Monoid m => (a -> m) -> Report a -> m
forall b a. (b -> a -> b) -> b -> Report a -> b
forall a b. (a -> b -> b) -> b -> Report a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Report a -> a
$cproduct :: forall a. Num a => Report a -> a
sum :: Report a -> a
$csum :: forall a. Num a => Report a -> a
minimum :: Report a -> a
$cminimum :: forall a. Ord a => Report a -> a
maximum :: Report a -> a
$cmaximum :: forall a. Ord a => Report a -> a
elem :: a -> Report a -> Bool
$celem :: forall a. Eq a => a -> Report a -> Bool
length :: Report a -> Int
$clength :: forall a. Report a -> Int
null :: Report a -> Bool
$cnull :: forall a. Report a -> Bool
toList :: Report a -> [a]
$ctoList :: forall a. Report a -> [a]
foldl1 :: (a -> a -> a) -> Report a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Report a -> a
foldr1 :: (a -> a -> a) -> Report a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Report a -> a
foldl' :: (b -> a -> b) -> b -> Report a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Report a -> b
foldl :: (b -> a -> b) -> b -> Report a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Report a -> b
foldr' :: (a -> b -> b) -> b -> Report a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Report a -> b
foldr :: (a -> b -> b) -> b -> Report a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Report a -> b
foldMap' :: (a -> m) -> Report a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Report a -> m
foldMap :: (a -> m) -> Report a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Report a -> m
fold :: Report m -> m
$cfold :: forall m. Monoid m => Report m -> m
Foldable,b -> Report p -> Report p
NonEmpty (Report p) -> Report p
Report p -> Report p -> Report p
(Report p -> Report p -> Report p)
-> (NonEmpty (Report p) -> Report p)
-> (forall b. Integral b => b -> Report p -> Report p)
-> Semigroup (Report p)
forall b. Integral b => b -> Report p -> Report p
forall p. NonEmpty (Report p) -> Report p
forall p. Report p -> Report p -> Report p
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall p b. Integral b => b -> Report p -> Report p
stimes :: b -> Report p -> Report p
$cstimes :: forall p b. Integral b => b -> Report p -> Report p
sconcat :: NonEmpty (Report p) -> Report p
$csconcat :: forall p. NonEmpty (Report p) -> Report p
<> :: Report p -> Report p -> Report p
$c<> :: forall p. Report p -> Report p -> Report p
Semigroup,Semigroup (Report p)
Report p
Semigroup (Report p)
-> Report p
-> (Report p -> Report p -> Report p)
-> ([Report p] -> Report p)
-> Monoid (Report p)
[Report p] -> Report p
Report p -> Report p -> Report p
forall p. Semigroup (Report p)
forall p. Report p
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall p. [Report p] -> Report p
forall p. Report p -> Report p -> Report p
mconcat :: [Report p] -> Report p
$cmconcat :: forall p. [Report p] -> Report p
mappend :: Report p -> Report p -> Report p
$cmappend :: forall p. Report p -> Report p -> Report p
mempty :: Report p
$cmempty :: forall p. Report p
$cp1Monoid :: forall p. Semigroup (Report p)
Monoid,(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Report a -> ShowS
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [Report a] -> ShowS
(forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Report a -> ShowS)
-> (forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [Report a] -> ShowS)
-> Show1 Report
forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Report a -> ShowS
forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [Report a] -> ShowS
forall (f :: * -> *).
(forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS)
-> (forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS)
-> Show1 f
liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Report a] -> ShowS
$cliftShowList :: forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [Report a] -> ShowS
liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Report a -> ShowS
$cliftShowsPrec :: forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Report a -> ShowS
Show1,(a -> b -> Bool) -> Report a -> Report b -> Bool
(forall a b. (a -> b -> Bool) -> Report a -> Report b -> Bool)
-> Eq1 Report
forall a b. (a -> b -> Bool) -> Report a -> Report b -> Bool
forall (f :: * -> *).
(forall a b. (a -> b -> Bool) -> f a -> f b -> Bool) -> Eq1 f
liftEq :: (a -> b -> Bool) -> Report a -> Report b -> Bool
$cliftEq :: forall a b. (a -> b -> Bool) -> Report a -> Report b -> Bool
Eq1)
instance Measured (Report p) (Report p) where
measure :: Report p -> Report p
measure = Report p -> Report p
forall a. a -> a
id
instance LabeledMeasure Report where
labeledMeasure :: [a] -> Report a
labeledMeasure = [a] -> Report a
forall a. [a] -> Report a
Report
newtype Count a = Count { Count a -> Int
getCount :: Int } deriving (Int -> Count a -> ShowS
[Count a] -> ShowS
Count a -> String
(Int -> Count a -> ShowS)
-> (Count a -> String) -> ([Count a] -> ShowS) -> Show (Count a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (a :: k). Int -> Count a -> ShowS
forall k (a :: k). [Count a] -> ShowS
forall k (a :: k). Count a -> String
showList :: [Count a] -> ShowS
$cshowList :: forall k (a :: k). [Count a] -> ShowS
show :: Count a -> String
$cshow :: forall k (a :: k). Count a -> String
showsPrec :: Int -> Count a -> ShowS
$cshowsPrec :: forall k (a :: k). Int -> Count a -> ShowS
Show,ReadPrec [Count a]
ReadPrec (Count a)
Int -> ReadS (Count a)
ReadS [Count a]
(Int -> ReadS (Count a))
-> ReadS [Count a]
-> ReadPrec (Count a)
-> ReadPrec [Count a]
-> Read (Count a)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k (a :: k). ReadPrec [Count a]
forall k (a :: k). ReadPrec (Count a)
forall k (a :: k). Int -> ReadS (Count a)
forall k (a :: k). ReadS [Count a]
readListPrec :: ReadPrec [Count a]
$creadListPrec :: forall k (a :: k). ReadPrec [Count a]
readPrec :: ReadPrec (Count a)
$creadPrec :: forall k (a :: k). ReadPrec (Count a)
readList :: ReadS [Count a]
$creadList :: forall k (a :: k). ReadS [Count a]
readsPrec :: Int -> ReadS (Count a)
$creadsPrec :: forall k (a :: k). Int -> ReadS (Count a)
Read,Count a -> Count a -> Bool
(Count a -> Count a -> Bool)
-> (Count a -> Count a -> Bool) -> Eq (Count a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (a :: k). Count a -> Count a -> Bool
/= :: Count a -> Count a -> Bool
$c/= :: forall k (a :: k). Count a -> Count a -> Bool
== :: Count a -> Count a -> Bool
$c== :: forall k (a :: k). Count a -> Count a -> Bool
Eq,Eq (Count a)
Eq (Count a)
-> (Count a -> Count a -> Ordering)
-> (Count a -> Count a -> Bool)
-> (Count a -> Count a -> Bool)
-> (Count a -> Count a -> Bool)
-> (Count a -> Count a -> Bool)
-> (Count a -> Count a -> Count a)
-> (Count a -> Count a -> Count a)
-> Ord (Count a)
Count a -> Count a -> Bool
Count a -> Count a -> Ordering
Count a -> Count a -> Count a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall k (a :: k). Eq (Count a)
forall k (a :: k). Count a -> Count a -> Bool
forall k (a :: k). Count a -> Count a -> Ordering
forall k (a :: k). Count a -> Count a -> Count a
min :: Count a -> Count a -> Count a
$cmin :: forall k (a :: k). Count a -> Count a -> Count a
max :: Count a -> Count a -> Count a
$cmax :: forall k (a :: k). Count a -> Count a -> Count a
>= :: Count a -> Count a -> Bool
$c>= :: forall k (a :: k). Count a -> Count a -> Bool
> :: Count a -> Count a -> Bool
$c> :: forall k (a :: k). Count a -> Count a -> Bool
<= :: Count a -> Count a -> Bool
$c<= :: forall k (a :: k). Count a -> Count a -> Bool
< :: Count a -> Count a -> Bool
$c< :: forall k (a :: k). Count a -> Count a -> Bool
compare :: Count a -> Count a -> Ordering
$ccompare :: forall k (a :: k). Count a -> Count a -> Ordering
$cp1Ord :: forall k (a :: k). Eq (Count a)
Ord)
instance Show1 Count where
liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Count a -> ShowS
liftShowsPrec Int -> a -> ShowS
_ [a] -> ShowS
_ = Int -> Count a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec
instance Eq1 Count where
liftEq :: (a -> b -> Bool) -> Count a -> Count b -> Bool
liftEq a -> b -> Bool
_ (Count Int
a) (Count Int
b) = Int
a Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
b
instance LabeledMeasure Count where
labeledMeasure :: [a] -> Count a
labeledMeasure = Int -> Count a
forall k (a :: k). Int -> Count a
Count (Int -> Count a) -> ([a] -> Int) -> [a] -> Count a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length
instance Monoid (Count a) where
mempty :: Count a
mempty = Int -> Count a
forall k (a :: k). Int -> Count a
Count Int
0
instance Semigroup (Count a) where
(Count Int
l) <> :: Count a -> Count a -> Count a
<> (Count Int
r) = Int -> Count a
forall k (a :: k). Int -> Count a
Count (Int -> Count a) -> Int -> Count a
forall a b. (a -> b) -> a -> b
$ Int
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
r
type (:*:) l r = Product l r
instance (LabeledMeasure l, LabeledMeasure r) => LabeledMeasure (l :*: r) where
labeledMeasure :: [a] -> (:*:) l r a
labeledMeasure [a]
xs = l a -> r a -> (:*:) l r a
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair ([a] -> l a
forall (v :: * -> *) a. LabeledMeasure v => [a] -> v a
labeledMeasure [a]
xs) ([a] -> r a
forall (v :: * -> *) a. LabeledMeasure v => [a] -> v a
labeledMeasure [a]
xs)
instance (Semigroup (l a), Semigroup (r a)) => Semigroup ((l :*: r) a) where
(Pair l a
l r a
r) <> :: (:*:) l r a -> (:*:) l r a -> (:*:) l r a
<> (Pair l a
l' r a
r') = l a -> r a -> (:*:) l r a
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair (l a
l l a -> l a -> l a
forall a. Semigroup a => a -> a -> a
<> l a
l') (r a
r r a -> r a -> r a
forall a. Semigroup a => a -> a -> a
<> r a
r')
instance (Monoid (l a), Monoid (r a)) => Monoid ((l :*: r) a) where
mempty :: (:*:) l r a
mempty = l a -> r a -> (:*:) l r a
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair l a
forall a. Monoid a => a
mempty r a
forall a. Monoid a => a
mempty