-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A library for easy manipulation of intervals according to their -- overlap. @package interval-patterns @version 0.1.0.0 module Data.OneOrTwo -- | Either one of something, or two of it. -- -- Use oneOrTwo to deconstruct. data OneOrTwo x One :: !x -> OneOrTwo x Two :: !x -> !x -> OneOrTwo x -- | Apply a oneOrTwo argument function appropriately. oneOrTwo :: (x -> a) -> (x -> x -> a) -> OneOrTwo x -> a instance Data.Traversable.Traversable Data.OneOrTwo.OneOrTwo instance Data.Foldable.Foldable Data.OneOrTwo.OneOrTwo instance GHC.Base.Functor Data.OneOrTwo.OneOrTwo instance Data.Data.Data x => Data.Data.Data (Data.OneOrTwo.OneOrTwo x) instance GHC.Generics.Generic (Data.OneOrTwo.OneOrTwo x) instance GHC.Read.Read x => GHC.Read.Read (Data.OneOrTwo.OneOrTwo x) instance GHC.Show.Show x => GHC.Show.Show (Data.OneOrTwo.OneOrTwo x) instance GHC.Classes.Ord x => GHC.Classes.Ord (Data.OneOrTwo.OneOrTwo x) instance GHC.Classes.Eq x => GHC.Classes.Eq (Data.OneOrTwo.OneOrTwo x) -- | Intervals over types and their operations. module Data.Interval -- | The kinds of extremum an interval can have. data Extremum Minimum :: Extremum Infimum :: Extremum Supremum :: Extremum Maximum :: Extremum -- | The opposite of an extremum is how it would be viewed from the -- other "direction" of how it is currently. -- -- c.f. opposeBound. opposite :: Extremum -> Extremum -- | A Bound is an endpoint of an Interval. data Bound ext x [Min] :: !x -> Bound Minimum x [Inf] :: !x -> Bound Infimum x [Sup] :: !x -> Bound Supremum x [Max] :: !x -> Bound Maximum x -- | Extract the term from a Bound. unBound :: Bound ext x -> x -- | A type class for inverting Bounds. class (Opposite (Opposite ext) ~ ext) => Bounding ext where { type family Opposite ext :: Extremum; } bound :: Bounding ext => x -> Bound ext x -- | c.f. opposite. opposeBound :: Bounding ext => Bound ext x -> Bound (Opposite ext) x -- | Bounds have special comparison rules for identical points. -- --
-- lower = fst . bounds --lower :: Ord x => Interval x -> SomeBound (Levitated x) -- | Get the lower bound of an interval (with the bound expressed at the -- term level). lowerBound :: Ord x => Interval x -> (Levitated x, Extremum) -- | Get the upper bound of an interval. -- --
-- upper = snd . bounds --upper :: Ord x => Interval x -> SomeBound (Levitated x) -- | Get the upper bound of an interval (with the bound expressed at the -- term level). upperBound :: Ord x => Interval x -> (Levitated x, Extremum) -- | Given SomeBounds, try to make an interval. interval :: Ord x => SomeBound (Levitated x) -> SomeBound (Levitated x) -> Interval x -- | Get the minimum of an interval, if it exists. imin :: Ord x => Interval x -> Maybe (Bound Minimum (Levitated x)) -- | Get the infimum of an interval, weakening if necessary. iinf :: Ord x => Interval x -> Bound Infimum (Levitated x) -- | Get the supremum of an interval, weakening if necessary. isup :: Ord x => Interval x -> Bound Supremum (Levitated x) -- | Get the maximum of an interval if it exists. imax :: Ord x => Interval x -> Maybe (Bound Maximum (Levitated x)) -- | Get the convex hull of two intervals. -- --
-- >>> hull (7 :|>: 8) (3 :|>: 4) -- (Levitate 3 :|->: Levitate 8) ---- --
-- >>> hull (Bottom :<-|: 3) (3 :<|: 4) -- (Bottom :<-|: Levitate 4) --hull :: Ord x => Interval x -> Interval x -> Interval x -- | Get the convex hull of a non-empty list of intervals. hulls :: Ord x => NonEmpty (Interval x) -> Interval x -- | Test whether a point is contained in the interval. within :: Ord x => x -> Interval x -> Bool -- | Create the closed-closed interval at a given point. point :: Ord x => x -> Interval x -- | Open both bounds of the given interval. open :: Ord x => Interval x -> Interval x -- | Close both bounds of the given interval. close :: Ord x => Interval x -> Interval x -- | Make the interval open-closed, leaving the endpoints unchanged. openclosed :: Ord x => Interval x -> Interval x -- | Make the interval closed-open, leaving the endpoints unchanged. closedopen :: Ord x => Interval x -> Interval x -- | Make the lower bound open, leaving the endpoints unchanged. openLower :: Ord x => Interval x -> Interval x -- | Make the lower bound closed, leaving the endpoints unchanged. closedLower :: Ord x => Interval x -> Interval x -- | Make the upper bound open, leaving the endpoints unchanged. openUpper :: Ord x => Interval x -> Interval x -- | Make the upper bound closed, leaving the endpoints unchanged. closedUpper :: Ord x => Interval x -> Interval x setLower :: Ord x => Levitated x -> Interval x -> Interval x setUpper :: Ord x => Levitated x -> Interval x -> Interval x -- | According to Allen, two intervals can be "adjacent" in 13 -- different ways, into at most 3 distinct intervals. In this package, -- this quality is called the Adjacency of the intervals. data Adjacency x Before :: !Interval x -> !Interval x -> Adjacency x Meets :: !Interval x -> !Interval x -> !Interval x -> Adjacency x Overlaps :: !Interval x -> !Interval x -> !Interval x -> Adjacency x Starts :: !Interval x -> !Interval x -> Adjacency x During :: !Interval x -> !Interval x -> !Interval x -> Adjacency x Finishes :: !Interval x -> !Interval x -> Adjacency x Identical :: !Interval x -> Adjacency x FinishedBy :: !Interval x -> !Interval x -> Adjacency x Contains :: !Interval x -> !Interval x -> !Interval x -> Adjacency x StartedBy :: !Interval x -> !Interval x -> Adjacency x OverlappedBy :: !Interval x -> !Interval x -> !Interval x -> Adjacency x MetBy :: !Interval x -> !Interval x -> !Interval x -> Adjacency x After :: !Interval x -> !Interval x -> Adjacency x -- | The result of having compared the same two intervals in reverse order. converseAdjacency :: Adjacency x -> Adjacency x -- | Calculate the Adjacency between two intervals, according to -- Allen. adjacency :: Ord x => Interval x -> Interval x -> Adjacency x -- | Calculate the intersection of two intervals, if it exists. -- --
-- >>> intersect (2 :<>: 4) (3 :||: 5) -- Just (Levitate 3 :|->: Levitate 4) -- -- >>> intersect (2 :<>: 4) (4 :||: 5) -- Nothing -- -- >>> intersect (1 :<>: 4) (2 :||: 3) -- Just (Levitate 2 :|-|: Levitate 3) --intersect :: forall x. Ord x => Interval x -> Interval x -> Maybe (Interval x) -- | Get the union of two intervals, as either OneOrTwo. -- --
-- >>> union (2 :||: 5) (5 :<>: 7) -- One (Levitate 2 :|->: Levitate 7) -- -- >>> union (2 :||: 4) (5 :<>: 7) -- Two (Levitate 2 :|-|: Levitate 4) (Levitate 5 :-: Levitate 7) --union :: forall x. Ord x => Interval x -> Interval x -> OneOrTwo (Interval x) -- | O(n log n). Get the union of a list of intervals. -- -- This function uses sort. See also unionsAsc. unions :: forall x. Ord x => [Interval x] -> [Interval x] -- | O(n). Get the union of a sorted list of intervals. -- -- NOTE: The input condition is not checked. Use with care. unionsAsc :: forall x. Ord x => [Interval x] -> [Interval x] -- | Take the complement of the interval, as possibly OneOrTwo. -- --
-- >>> complement (3 :<>: 4) -- Just (Two (Bottom :|-|: Levitate 3) (Levitate 4 :|-|: Top)) --complement :: forall x. Ord x => Interval x -> Maybe (OneOrTwo (Interval x)) -- | Remove all points of the second interval from the first. -- --
-- >>> difference Whole (3 :<>: 4) -- Just (Two (Bottom :|-|: Levitate 3) (Levitate 4 :|-|: Top)) -- -- >>> difference (1 :<>: 4) (2 :||: 3) -- Just (Two (Levitate 1 :-: Levitate 2) (Levitate 3 :-: Levitate 4)) --difference :: forall x. Ord x => Interval x -> Interval x -> Maybe (OneOrTwo (Interval x)) -- | Infix synonym for difference (\\) :: forall x. Ord x => Interval x -> Interval x -> Maybe (OneOrTwo (Interval x)) -- | The difference of the union and intersection of two intervals. -- --
-- >>> symmetricDifference Whole (3 :<>: 4) -- Just (Two (Bottom :|-|: Levitate 3) (Levitate 4 :|-|: Top)) -- -- >>> symmetricDifference (1 :<>: 4) (2 :||: 3) -- Just (Two (Levitate 1 :-: Levitate 2) (Levitate 3 :-: Levitate 4)) --symmetricDifference :: forall x. Ord x => Interval x -> Interval x -> Maybe (OneOrTwo (Interval x)) -- | Get the measure of an interval. -- --
-- >>> measure (-1 :<>: 1) -- Just 2 -- -- >>> measure (Bottom :-: Levitate 1) -- Nothing --measure :: forall x. (Ord x, Num x) => Interval x -> Maybe x -- | Apply a function to the lower, then upper, endpoint of an interval. -- --
-- >>> measuring max (-1 :<>: 1) -- Just 1 -- -- >>> measuring min (-1 :<>: 1) -- Just (-1) --measuring :: forall y x. (Ord x, Num y) => (x -> x -> y) -> Interval x -> Maybe y -- | Get the distance between two intervals, or 0 if they adjacency. -- --
-- >>> hausdorff (3 :<>: 5) (6 :<>: 7) -- Just 1 -- -- >>> hausdorff (3 :<>: 5) Whole -- Just 0 --hausdorff :: (Ord x, Num x) => Interval x -> Interval x -> Maybe x -- | m +/- r creates the closed interval centred at -- m with radius r. -- -- For the open interval, simply write open (x +/- -- y). (+/-) :: (Ord x, Num x) => x -> x -> Interval x instance Data.Data.Data Data.Interval.Extremum instance GHC.Generics.Generic Data.Interval.Extremum instance GHC.Read.Read Data.Interval.Extremum instance GHC.Show.Show Data.Interval.Extremum instance GHC.Enum.Bounded Data.Interval.Extremum instance GHC.Enum.Enum Data.Interval.Extremum instance GHC.Classes.Ord Data.Interval.Extremum instance GHC.Classes.Eq Data.Interval.Extremum instance GHC.Generics.Generic (Data.Interval.Adjacency x) instance (GHC.Classes.Ord x, GHC.Show.Show x) => GHC.Show.Show (Data.Interval.Adjacency x) instance GHC.Classes.Ord x => GHC.Classes.Ord (Data.Interval.Adjacency x) instance GHC.Classes.Ord x => GHC.Classes.Eq (Data.Interval.Adjacency x) instance GHC.Classes.Ord x => GHC.Classes.Eq (Data.Interval.Interval x) instance (GHC.Classes.Ord x, GHC.Show.Show x) => GHC.Show.Show (Data.Interval.Interval x) instance GHC.Classes.Ord x => GHC.Classes.Ord (Data.Interval.Interval x) instance GHC.Classes.Eq x => GHC.Classes.Eq (Data.Interval.SomeBound (Algebra.Lattice.Levitated.Levitated x)) instance GHC.Classes.Ord x => GHC.Classes.Ord (Data.Interval.SomeBound (Algebra.Lattice.Levitated.Levitated x)) instance Data.Interval.Bounding 'Data.Interval.Minimum instance Data.Interval.Bounding 'Data.Interval.Infimum instance Data.Interval.Bounding 'Data.Interval.Supremum instance Data.Interval.Bounding 'Data.Interval.Maximum instance GHC.Base.Functor (Data.Interval.Bound ext) instance Data.Foldable.Foldable (Data.Interval.Bound ext) instance Data.Traversable.Traversable (Data.Interval.Bound ext) instance GHC.Classes.Eq x => GHC.Classes.Eq (Data.Interval.Bound ext x) instance GHC.Classes.Ord x => GHC.Classes.Ord (Data.Interval.Bound ext (Algebra.Lattice.Levitated.Levitated x)) module Data.Interval.Borel -- | The Borel sets on a type are the sets generated by its open -- intervals. It forms a Heyting algebra with union as join -- and intersection as meet, and a Ring with -- symmetricDifference as addition and intersection as -- multiplication (and complement as negation). In fact the -- algebra is Boolean as the operation x ==> y = -- complement x \/ y. -- -- It is a monoid that is convenient for agglomerating groups of -- intervals, such as for calculating the overall timespan of a group of -- events. However, it is agnostic of how many times each given point has -- been covered. To keep track of this data, use Layers. data Borel x -- | Consider the Borel set identified by a list of -- Intervals. borel :: Ord x => [Interval x] -> Borel x -- | Turn a Borel set into a Set of Intervals. intervalSet :: Ord x => Borel x -> Set (Interval x) -- | The empty Borel set. empty :: Ord x => Borel x -- | The Borel set consisting of a single Interval. singleton :: Ord x => Interval x -> Borel x -- | Is this Borel set empty? null :: Borel x -> Bool -- | Insert an Interval into a Borel set, agglomerating along -- the way. insert :: Ord x => Interval x -> Borel x -> Borel x -- | The maximal Borel set, that covers the entire range. whole :: Ord x => Borel x -- | Completely remove an Interval from a Borel set. cutout :: Ord x => Interval x -> Borel x -> Borel x -- | Is this point within any connected component of the -- Borel set? member :: Ord x => x -> Borel x -> Bool -- | Is this point not within any connected component of the -- Borel set? notMember :: Ord x => x -> Borel x -> Bool -- | A synonym for (<>). union :: Ord x => Borel x -> Borel x -> Borel x -- | A synonym for fold. unions :: Ord x => [Borel x] -> Borel x -- | Remove all intervals of the second set from the first. difference :: Ord x => Borel x -> Borel x -> Borel x -- | Take the symmetric difference of two Borel sets. symmetricDifference :: Ord x => Borel x -> Borel x -> Borel x -- | Take the Borel set consisting of each point not in the given -- one. complement :: Ord x => Borel x -> Borel x -- | Take the intersection of two Borel sets. intersection :: Ord x => Borel x -> Borel x -> Borel x -- | Take the intersection of a list of Borel sets. intersections :: Ord x => [Borel x] -> Borel x -- | Take the smallest spanning Interval of a Borel set, -- provided that it is not the empty set. hull :: Ord x => Borel x -> Maybe (Interval x) instance GHC.Generics.Generic (Data.Interval.Borel.Borel x) instance (GHC.Classes.Ord x, GHC.Show.Show x) => GHC.Show.Show (Data.Interval.Borel.Borel x) instance GHC.Classes.Ord x => GHC.Classes.Ord (Data.Interval.Borel.Borel x) instance GHC.Classes.Ord x => GHC.Classes.Eq (Data.Interval.Borel.Borel x) instance GHC.Classes.Ord x => Relude.Container.One.One (Data.Interval.Borel.Borel x) instance GHC.Classes.Ord x => GHC.Base.Semigroup (Data.Interval.Borel.Borel x) instance GHC.Classes.Ord x => GHC.Base.Monoid (Data.Interval.Borel.Borel x) instance (GHC.Classes.Ord x, Algebra.Lattice.Lattice x) => Algebra.Lattice.Lattice (Data.Interval.Borel.Borel x) instance (GHC.Classes.Ord x, Algebra.Lattice.Lattice x) => Algebra.Lattice.BoundedMeetSemiLattice (Data.Interval.Borel.Borel x) instance (GHC.Classes.Ord x, Algebra.Lattice.Lattice x) => Algebra.Lattice.BoundedJoinSemiLattice (Data.Interval.Borel.Borel x) instance (GHC.Classes.Ord x, Algebra.Lattice.Lattice x) => Algebra.Heyting.Heyting (Data.Interval.Borel.Borel x) instance (GHC.Classes.Ord x, Algebra.Lattice.Lattice x) => Data.Semiring.Semiring (Data.Interval.Borel.Borel x) instance (GHC.Classes.Ord x, Algebra.Lattice.Lattice x) => Data.Semiring.Ring (Data.Interval.Borel.Borel x) module Data.Interval.Layers data Layers x y -- | Draw the Layers of specified bases and thicknesses. fromList :: (Ord x, Semigroup y) => [(Interval x, y)] -> Layers x y -- | Get all of the bases and thicknesses in the Layers. toList :: Ord x => Layers x y -> [(Interval x, y)] -- | A blank canvas. empty :: Layers x y -- | singleton ix y is the rectangle with base ix of -- thickness y. singleton :: Ord x => Interval x -> y -> Layers x y -- | insert ix y l draws over l a rectangle with base -- ix of thickness y. insert :: (Ord x, Semigroup y) => Interval x -> y -> Layers x y -> Layers x y -- | Ignore the Layers and focus only on whether points are -- within any contained Interval or not. squash :: Ord x => Layers x y -> Borel x -- | Get the thickness of the Layers at a point. thickness :: (Ord x, Monoid y) => x -> Layers x y -> y -- | Where and how thick is the thickest Interval? thickest :: (Ord x, Ord y) => Layers x y -> Maybe (Interval x, y) -- | Take away a thickness over a given base from the Layers. remove :: (Ord x, Group y) => y -> Interval x -> Layers x y -> Layers x y -- | Add the given thickness to every point. baseline :: (Ord x, Semigroup y) => y -> Layers x y -> Layers x y nestings :: (Ord x, Semigroup y) => [(Interval x, y)] -> [(Interval x, y)] nestingsAsc :: (Ord x, Semigroup y) => [(Interval x, y)] -> [(Interval x, y)] instance GHC.Generics.Generic (Data.Interval.Layers.Layers x y) instance GHC.Base.Functor (Data.Interval.Layers.Layers x) instance (GHC.Classes.Ord x, GHC.Show.Show x, GHC.Show.Show y) => GHC.Show.Show (Data.Interval.Layers.Layers x y) instance (GHC.Classes.Ord x, GHC.Classes.Ord y) => GHC.Classes.Ord (Data.Interval.Layers.Layers x y) instance (GHC.Classes.Ord x, GHC.Classes.Eq y) => GHC.Classes.Eq (Data.Interval.Layers.Layers x y) instance (GHC.Classes.Ord x, GHC.Base.Semigroup y) => GHC.Base.Semigroup (Data.Interval.Layers.Layers x y) instance (GHC.Classes.Ord x, GHC.Base.Semigroup y) => GHC.Base.Monoid (Data.Interval.Layers.Layers x y) instance (GHC.Classes.Ord x, Data.Group.Group y) => Data.Group.Group (Data.Interval.Layers.Layers x y) module Data.Timeframe -- |
-- type Timeframe = Interval UTCTime --type Timeframe = Interval UTCTime localTimeframeAt :: TimeZone -> LocalTime -> LocalTime -> Timeframe localTimeframe :: MonadIO io => LocalTime -> LocalTime -> io Timeframe pureLocalTimeframe :: LocalTime -> LocalTime -> Timeframe duration :: Timeframe -> Maybe NominalDiffTime -- | An Event is something that happens for a period of time. -- --
-- type Event = Layers UTCTime --type Event = Layers UTCTime (Sum Int) event :: Timeframe -> Event newtype Calendar ev Calendar :: Map ev Event -> Calendar ev [getCalendar] :: Calendar ev -> Map ev Event singleton :: Ord ev => ev -> Event -> Calendar ev calendar :: Ord ev => ev -> Timeframe -> Calendar ev addEvent :: Ord ev => ev -> Event -> Calendar ev -> Calendar ev totalDuration :: Ord ev => ev -> Calendar ev -> Maybe NominalDiffTime instance GHC.Show.Show ev => GHC.Show.Show (Data.Timeframe.Calendar ev) instance GHC.Classes.Ord ev => GHC.Classes.Ord (Data.Timeframe.Calendar ev) instance GHC.Classes.Eq ev => GHC.Classes.Eq (Data.Timeframe.Calendar ev) instance GHC.Classes.Ord ev => GHC.Base.Semigroup (Data.Timeframe.Calendar ev) instance GHC.Classes.Ord ev => GHC.Base.Monoid (Data.Timeframe.Calendar ev)