{-# LANGUAGE ScopedTypeVariables, TypeApplications #-}
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
module IntervalAlgebra(
Intervallic(..)
, IntervalAlgebraic(..)
, IntervalCombinable(..)
, Moment(..)
, IntervalSizeable(..)
, IntervalFilterable(..)
, Interval
, IntervalRelation
, ComparativePredicateOf
) where
import Prelude (Eq, Ord, Show, Read
, Maybe(..), Either(..), String, Integer, Int, Bool(..), Num
, Foldable (maximum, minimum, foldMap, foldr)
, otherwise, flip, show, fst, snd, min, max, any, negate, not
, (++), (==), (&&), (<), (>), (<=), ($), (+), (-), (.))
import Data.Time as DT ( Day, addDays, diffDays, addGregorianYearsClip, calendarYear )
import Data.Semigroup ( Semigroup((<>)) )
import GHC.Base (Applicative(pure))
import Witherable ( Filterable(filter) )
newtype Interval a = Interval (a, a) deriving (Interval a -> Interval a -> Bool
(Interval a -> Interval a -> Bool)
-> (Interval a -> Interval a -> Bool) -> Eq (Interval a)
forall a. Eq a => Interval a -> Interval a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Interval a -> Interval a -> Bool
$c/= :: forall a. Eq a => Interval a -> Interval a -> Bool
== :: Interval a -> Interval a -> Bool
$c== :: forall a. Eq a => Interval a -> Interval a -> Bool
Eq)
data IntervalRelation =
Meets
| MetBy
| Before
| After
| Overlaps
| OverlappedBy
| Starts
| StartedBy
| Finishes
| FinishedBy
| During
| Contains
| Equals
deriving (Int -> IntervalRelation -> ShowS
[IntervalRelation] -> ShowS
IntervalRelation -> String
(Int -> IntervalRelation -> ShowS)
-> (IntervalRelation -> String)
-> ([IntervalRelation] -> ShowS)
-> Show IntervalRelation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IntervalRelation] -> ShowS
$cshowList :: [IntervalRelation] -> ShowS
show :: IntervalRelation -> String
$cshow :: IntervalRelation -> String
showsPrec :: Int -> IntervalRelation -> ShowS
$cshowsPrec :: Int -> IntervalRelation -> ShowS
Show, ReadPrec [IntervalRelation]
ReadPrec IntervalRelation
Int -> ReadS IntervalRelation
ReadS [IntervalRelation]
(Int -> ReadS IntervalRelation)
-> ReadS [IntervalRelation]
-> ReadPrec IntervalRelation
-> ReadPrec [IntervalRelation]
-> Read IntervalRelation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IntervalRelation]
$creadListPrec :: ReadPrec [IntervalRelation]
readPrec :: ReadPrec IntervalRelation
$creadPrec :: ReadPrec IntervalRelation
readList :: ReadS [IntervalRelation]
$creadList :: ReadS [IntervalRelation]
readsPrec :: Int -> ReadS IntervalRelation
$creadsPrec :: Int -> ReadS IntervalRelation
Read)
type ComparativePredicateOf a = (a -> a -> Bool)
class (Ord a, Show a) => Intervallic a where
parseInterval :: a -> a -> Either String (Interval a)
parseInterval a
x a
y
| a
y a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
x = String -> Either String (Interval a)
forall a b. a -> Either a b
Left (String -> Either String (Interval a))
-> String -> Either String (Interval a)
forall a b. (a -> b) -> a -> b
$ a -> String
forall a. Show a => a -> String
show a
y String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"<" String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
x
| Bool
otherwise = Interval a -> Either String (Interval a)
forall a b. b -> Either a b
Right (Interval a -> Either String (Interval a))
-> Interval a -> Either String (Interval a)
forall a b. (a -> b) -> a -> b
$ (a, a) -> Interval a
forall a. (a, a) -> Interval a
Interval (a
x, a
y)
unsafeInterval :: a -> a -> Interval a
unsafeInterval a
x a
y = (a, a) -> Interval a
forall a. (a, a) -> Interval a
Interval (a
x, a
y)
begin, end :: Interval a -> a
begin (Interval (a, a)
x) = (a, a) -> a
forall a b. (a, b) -> a
fst (a, a)
x
end (Interval (a, a)
x) = (a, a) -> a
forall a b. (a, b) -> b
snd (a, a)
x
class (Eq a, Intervallic a) => IntervalAlgebraic a where
relate :: Interval a -> Interval a -> IntervalRelation
relate Interval a
x Interval a
y
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`before` Interval a
y = IntervalRelation
Before
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`after` Interval a
y = IntervalRelation
After
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`meets` Interval a
y = IntervalRelation
Meets
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`metBy` Interval a
y = IntervalRelation
MetBy
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`overlaps` Interval a
y = IntervalRelation
Overlaps
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`overlappedBy` Interval a
y = IntervalRelation
OverlappedBy
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`starts` Interval a
y = IntervalRelation
Starts
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`startedBy` Interval a
y = IntervalRelation
StartedBy
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`finishes` Interval a
y = IntervalRelation
Finishes
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`finishedBy` Interval a
y = IntervalRelation
FinishedBy
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`during` Interval a
y = IntervalRelation
During
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`contains` Interval a
y = IntervalRelation
Contains
| Bool
otherwise = IntervalRelation
Equals
equals :: ComparativePredicateOf (Interval a)
equals Interval a
x Interval a
y = Interval a
x ComparativePredicateOf (Interval a)
forall a. Eq a => a -> a -> Bool
== Interval a
y
meets, metBy :: ComparativePredicateOf (Interval a)
meets Interval a
x Interval a
y = Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
y
metBy = ComparativePredicateOf (Interval a)
-> ComparativePredicateOf (Interval a)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
meets
before, after :: ComparativePredicateOf (Interval a)
before Interval a
x Interval a
y = Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
y
after = ComparativePredicateOf (Interval a)
-> ComparativePredicateOf (Interval a)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
before
overlaps, overlappedBy :: ComparativePredicateOf (Interval a)
overlaps Interval a
x Interval a
y = Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
y Bool -> Bool -> Bool
&& Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
y Bool -> Bool -> Bool
&& Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
y
overlappedBy = ComparativePredicateOf (Interval a)
-> ComparativePredicateOf (Interval a)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
overlaps
starts, startedBy :: ComparativePredicateOf (Interval a)
starts Interval a
x Interval a
y = Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
y Bool -> Bool -> Bool
&& (Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
y)
startedBy = ComparativePredicateOf (Interval a)
-> ComparativePredicateOf (Interval a)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
starts
finishes, finishedBy :: ComparativePredicateOf (Interval a)
finishes Interval a
x Interval a
y = Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
y Bool -> Bool -> Bool
&& Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
y
finishedBy = ComparativePredicateOf (Interval a)
-> ComparativePredicateOf (Interval a)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
finishes
during, contains :: ComparativePredicateOf (Interval a)
during Interval a
x Interval a
y = Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
y Bool -> Bool -> Bool
&& Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
y
contains = ComparativePredicateOf (Interval a)
-> ComparativePredicateOf (Interval a)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
during
composeRelations :: [ComparativePredicateOf (Interval a)] ->
ComparativePredicateOf (Interval a)
composeRelations [ComparativePredicateOf (Interval a)]
fs Interval a
x Interval a
y = (ComparativePredicateOf (Interval a) -> Bool)
-> [ComparativePredicateOf (Interval a)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (\ ComparativePredicateOf (Interval a)
f -> ComparativePredicateOf (Interval a)
f Interval a
x Interval a
y) [ComparativePredicateOf (Interval a)]
fs
disjoint :: ComparativePredicateOf (Interval a)
disjoint = [ComparativePredicateOf (Interval a)]
-> ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
[ComparativePredicateOf (Interval a)]
-> ComparativePredicateOf (Interval a)
composeRelations [ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
before, ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
after, ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
meets, ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
metBy]
in' :: ComparativePredicateOf (Interval a)
in' = [ComparativePredicateOf (Interval a)]
-> ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
[ComparativePredicateOf (Interval a)]
-> ComparativePredicateOf (Interval a)
composeRelations [ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
during, ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
starts, ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
finishes, ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
equals]
class (Intervallic a, Num b, Ord b) => Moment a b| a -> b where
moment :: b
moment = b
1
class (Intervallic a, Moment a b, Num b, Ord b) => IntervalSizeable a b| a -> b where
duration :: Interval a -> b
add :: b -> a -> a
expand :: b -> b -> Interval a -> Interval a
expand b
l b
r Interval a
p = (a, a) -> Interval a
forall a. (a, a) -> Interval a
Interval (a
s, a
e)
where s :: a
s = b -> a -> a
forall a b. IntervalSizeable a b => b -> a -> a
add (b -> b
forall a. Num a => a -> a
negate (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$ b -> b -> b
forall a. Ord a => a -> a -> a
max b
l (forall b. Moment a b => b
forall a b. Moment a b => b
moment @a)) (Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
p)
e :: a
e = b -> a -> a
forall a b. IntervalSizeable a b => b -> a -> a
add (b -> b -> b
forall a. Ord a => a -> a -> a
min b
r (forall b. Moment a b => b
forall a b. Moment a b => b
moment @a)) (Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
p)
expandl :: b -> Interval a -> Interval a
expandl b
i = b -> b -> Interval a -> Interval a
forall a b.
IntervalSizeable a b =>
b -> b -> Interval a -> Interval a
expand b
i b
0
expandr :: b -> Interval a -> Interval a
expandr = b -> b -> Interval a -> Interval a
forall a b.
IntervalSizeable a b =>
b -> b -> Interval a -> Interval a
expand b
0
beginerval :: b -> a -> Interval a
beginerval b
dur a
x = (a, a) -> Interval a
forall a. (a, a) -> Interval a
Interval (a
x, b -> a -> a
forall a b. IntervalSizeable a b => b -> a -> a
add (b -> b -> b
forall a. Ord a => a -> a -> a
max (forall b. Moment a b => b
forall a b. Moment a b => b
moment @a) b
dur) a
x)
enderval :: b -> a -> Interval a
enderval b
dur a
x = (a, a) -> Interval a
forall a. (a, a) -> Interval a
Interval (b -> a -> a
forall a b. IntervalSizeable a b => b -> a -> a
add (b -> b
forall a. Num a => a -> a
negate (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$ b -> b -> b
forall a. Ord a => a -> a -> a
max (forall b. Moment a b => b
forall a b. Moment a b => b
moment @a) b
dur) a
x, a
x)
class (IntervalAlgebraic a) => IntervalCombinable a where
(.+.) :: Interval a -> Interval a -> Maybe (Interval a)
(.+.) Interval a
x Interval a
y
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`meets` Interval a
y = Interval a -> Maybe (Interval a)
forall a. a -> Maybe a
Just (Interval a -> Maybe (Interval a))
-> Interval a -> Maybe (Interval a)
forall a b. (a -> b) -> a -> b
$ (a, a) -> Interval a
forall a. (a, a) -> Interval a
Interval (Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
x, Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
y)
| Bool
otherwise = Maybe (Interval a)
forall a. Maybe a
Nothing
extenterval :: Interval a -> Interval a -> Interval a
extenterval Interval a
x Interval a
y = (a, a) -> Interval a
forall a. (a, a) -> Interval a
Interval (a
s, a
e)
where s :: a
s = a -> a -> a
forall a. Ord a => a -> a -> a
min (Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
x) (Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
y)
e :: a
e = a -> a -> a
forall a. Ord a => a -> a -> a
max (Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
x) (Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
y)
(><) :: Interval a -> Interval a -> Maybe (Interval a)
(><) Interval a
x Interval a
y
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`before` Interval a
y = Interval a -> Maybe (Interval a)
forall a. a -> Maybe a
Just (Interval a -> Maybe (Interval a))
-> Interval a -> Maybe (Interval a)
forall a b. (a -> b) -> a -> b
$ (a, a) -> Interval a
forall a. (a, a) -> Interval a
Interval ( Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
x, Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
y )
| Bool
otherwise = Maybe (Interval a)
forall a. Maybe a
Nothing
(<+>):: (Semigroup (f (Interval a)), Applicative f) =>
Interval a ->
Interval a ->
f (Interval a)
(<+>) Interval a
x Interval a
y
| Interval a
x ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
`before` Interval a
y = Interval a -> f (Interval a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Interval a
x f (Interval a) -> f (Interval a) -> f (Interval a)
forall a. Semigroup a => a -> a -> a
<> Interval a -> f (Interval a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Interval a
y
| Bool
otherwise = Interval a -> f (Interval a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ( Interval a -> Interval a -> Interval a
forall a.
IntervalCombinable a =>
Interval a -> Interval a -> Interval a
extenterval Interval a
x Interval a
y )
class (Filterable f, IntervalAlgebraic a) => IntervalFilterable f a where
filterMaker :: ComparativePredicateOf (Interval a)
-> Interval a
-> (f (Interval a) -> f (Interval a))
filterMaker ComparativePredicateOf (Interval a)
f Interval a
p = (Interval a -> Bool) -> f (Interval a) -> f (Interval a)
forall (f :: * -> *) a. Filterable f => (a -> Bool) -> f a -> f a
Witherable.filter (ComparativePredicateOf (Interval a)
`f` Interval a
p)
filterOverlaps :: Interval a -> f (Interval a) -> f (Interval a)
filterOverlaps = ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
forall (f :: * -> *) a.
IntervalFilterable f a =>
ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
filterMaker ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
overlaps
filterOverlappedBy :: Interval a -> f (Interval a) -> f (Interval a)
filterOverlappedBy = ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
forall (f :: * -> *) a.
IntervalFilterable f a =>
ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
filterMaker ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
overlappedBy
filterBefore :: Interval a -> f (Interval a) -> f (Interval a)
filterBefore = ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
forall (f :: * -> *) a.
IntervalFilterable f a =>
ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
filterMaker ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
before
filterAfter :: Interval a -> f (Interval a) -> f (Interval a)
filterAfter = ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
forall (f :: * -> *) a.
IntervalFilterable f a =>
ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
filterMaker ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
after
filterMeets :: Interval a -> f (Interval a) -> f (Interval a)
filterMeets = ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
forall (f :: * -> *) a.
IntervalFilterable f a =>
ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
filterMaker ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
meets
filterMetBy :: Interval a -> f (Interval a) -> f (Interval a)
filterMetBy = ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
forall (f :: * -> *) a.
IntervalFilterable f a =>
ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
filterMaker ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
metBy
filterDuring :: Interval a -> f (Interval a) -> f (Interval a)
filterDuring = ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
forall (f :: * -> *) a.
IntervalFilterable f a =>
ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
filterMaker ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
during
filterContains :: Interval a -> f (Interval a) -> f (Interval a)
filterContains = ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
forall (f :: * -> *) a.
IntervalFilterable f a =>
ComparativePredicateOf (Interval a)
-> Interval a -> f (Interval a) -> f (Interval a)
filterMaker ComparativePredicateOf (Interval a)
forall a.
IntervalAlgebraic a =>
ComparativePredicateOf (Interval a)
contains
instance (Intervallic a) => Ord (Interval a) where
<= :: Interval a -> Interval a -> Bool
(<=) Interval a
x Interval a
y
| Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
y = Bool
True
| Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
y = Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
y
| Bool
otherwise = Bool
False
< :: Interval a -> Interval a -> Bool
(<) Interval a
x Interval a
y
| Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
y = Bool
True
| Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
y = Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
y
| Bool
otherwise = Bool
False
instance (Intervallic a, Show a) => Show (Interval a) where
show :: Interval a -> String
show Interval a
x = String
"(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show (Interval a -> a
forall a. Intervallic a => Interval a -> a
begin Interval a
x) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
", " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show (Interval a -> a
forall a. Intervallic a => Interval a -> a
end Interval a
x) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")"
instance Intervallic Int
instance IntervalAlgebraic Int
instance IntervalCombinable Int
instance Moment Int Int
instance IntervalSizeable Int Int where
add :: Int -> Int -> Int
add = Int -> Int -> Int
forall a. Num a => a -> a -> a
(+)
duration :: Interval Int -> Int
duration Interval Int
x = Interval Int -> Int
forall a. Intervallic a => Interval a -> a
end Interval Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Interval Int -> Int
forall a. Intervallic a => Interval a -> a
begin Interval Int
x
instance IntervalFilterable [] Int
instance Intervallic Integer
instance IntervalAlgebraic Integer
instance IntervalCombinable Integer
instance Moment Integer Integer
instance IntervalSizeable Integer Integer where
add :: Integer -> Integer -> Integer
add = Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
(+)
duration :: Interval Integer -> Integer
duration Interval Integer
x = Interval Integer -> Integer
forall a. Intervallic a => Interval a -> a
end Interval Integer
x Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Interval Integer -> Integer
forall a. Intervallic a => Interval a -> a
begin Interval Integer
x
instance IntervalFilterable [] Integer
instance Intervallic DT.Day
instance IntervalAlgebraic DT.Day
instance IntervalCombinable DT.Day
instance Moment DT.Day Integer
instance IntervalSizeable DT.Day Integer where
add :: Integer -> Day -> Day
add = Integer -> Day -> Day
addDays
duration :: Interval Day -> Integer
duration Interval Day
x = Day -> Day -> Integer
diffDays (Interval Day -> Day
forall a. Intervallic a => Interval a -> a
end Interval Day
x) (Interval Day -> Day
forall a. Intervallic a => Interval a -> a
begin Interval Day
x)
instance IntervalFilterable [] DT.Day