Copyright | (c) NoviSci Inc 2020 |
---|---|
License | BSD3 |
Maintainer | bsaul@novisci.com |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
The IntervalAlgebra
module provides data types and related classes for the
interval-based temporal logic described in Allen (1983)
and axiomatized in Allen and Hayes (1987).
A good primer on Allen's algebra can be found here.
Design
The module is built around three typeclasses designed to separate concerns of
constructing, relating, and combining
s: Interval
provides an interface to the data structure of anIntervallic
, defining how anInterval
is constructed.Interval
a
provides an interface to theIntervalAlgebraic
, the workhorse of Allen's temporal logic.IntervalRelation
s
provides an interface to methods of combining multipleIntervalCombinable
.Interval
s
An advantage of nested typeclass design is that developers can define an
of type Interval
a
with just the amount of structure that they need.
Total Ordering of Interval
s
The modules makes the (opinionated) choice of a total ordering for Intervallic
s. Namely, the ordering is based on first ordering the Interval
begin
s
then the end
s.
Development
This module is under development and the API may change in the future.
Synopsis
- class (Ord a, Show a) => Intervallic a where
- parseInterval :: a -> a -> Either String (Interval a)
- unsafeInterval :: a -> a -> Interval a
- begin, end :: Interval a -> a
- class (Eq a, Intervallic a) => IntervalAlgebraic a where
- relate :: Interval a -> Interval a -> IntervalRelation
- equals :: ComparativePredicateOf (Interval a)
- meets, metBy :: ComparativePredicateOf (Interval a)
- before, after :: ComparativePredicateOf (Interval a)
- overlaps, overlappedBy :: ComparativePredicateOf (Interval a)
- starts, startedBy :: ComparativePredicateOf (Interval a)
- finishes, finishedBy :: ComparativePredicateOf (Interval a)
- during, contains :: ComparativePredicateOf (Interval a)
- composeRelations :: [ComparativePredicateOf (Interval a)] -> ComparativePredicateOf (Interval a)
- disjoint :: ComparativePredicateOf (Interval a)
- in' :: ComparativePredicateOf (Interval a)
- class IntervalAlgebraic a => IntervalCombinable a where
- newtype Interval a = Interval (a, a)
- data IntervalRelation
- type ComparativePredicateOf a = a -> a -> Bool
Classes
class (Ord a, Show a) => Intervallic a where Source #
The
typeclass specifies how an Intervallic
s is constructed.
It also includes functions for getting the Interval
a
and begin
of an end
.Interval
a
Nothing
parseInterval :: a -> a -> Either String (Interval a) Source #
Safely parse a pair of a
s to create an
.Interval
a
unsafeInterval :: a -> a -> Interval a Source #
Create a new
. This function is not safe as it does
not enforce that \(x < y\). Use with caution. It is meant to be helper
function in early prototyping of this package. This function may be
deprecated in future releases.Interval
a
begin :: Interval a -> a Source #
Access the ends of an
.Interval
a
end :: Interval a -> a Source #
Access the ends of an
.Interval
a
Instances
Intervallic Int Source # | |
Intervallic Integer Source # | |
Intervallic Day Source # | |
class (Eq a, Intervallic a) => IntervalAlgebraic a where Source #
The
typeclass specifies the functions and relational
operators for interval-based temporal logic. The typeclass defines the
relational operators for intervals, plus other useful utilities such as
IntervalAlgebraic
, disjoint
, and in'
.composeRelations
Nothing
relate :: Interval a -> Interval a -> IntervalRelation Source #
Compare two intervals to determine their IntervalRelation
.
equals :: ComparativePredicateOf (Interval a) Source #
Does x equal y?
meets :: ComparativePredicateOf (Interval a) Source #
Does x meet y? Is y metBy x?
metBy :: ComparativePredicateOf (Interval a) Source #
Does x meet y? Is y metBy x?
before :: ComparativePredicateOf (Interval a) Source #
Is x before y? Is x after y?
after :: ComparativePredicateOf (Interval a) Source #
Is x before y? Is x after y?
overlaps :: ComparativePredicateOf (Interval a) Source #
Does x overlap y? Is x overlapped by y?
overlappedBy :: ComparativePredicateOf (Interval a) Source #
Does x overlap y? Is x overlapped by y?
starts :: ComparativePredicateOf (Interval a) Source #
Does x start y? Is x started by y?
startedBy :: ComparativePredicateOf (Interval a) Source #
Does x start y? Is x started by y?
finishes :: ComparativePredicateOf (Interval a) Source #
Does x finish y? Is x finished by y?
finishedBy :: ComparativePredicateOf (Interval a) Source #
Does x finish y? Is x finished by y?
during :: ComparativePredicateOf (Interval a) Source #
Is x during y? Does x contain y?
contains :: ComparativePredicateOf (Interval a) Source #
Is x during y? Does x contain y?
composeRelations :: [ComparativePredicateOf (Interval a)] -> ComparativePredicateOf (Interval a) Source #
Compose a list of interval relations with _or_ to create a new
.For example,
ComparativePredicateOf
Interval
acomposeRelations [before, meets]
creates a predicate function determining
if one interval is either before or meets another interval.
disjoint :: ComparativePredicateOf (Interval a) Source #
in' :: ComparativePredicateOf (Interval a) Source #
Instances
class IntervalAlgebraic a => IntervalCombinable a where Source #
The
typeclass provides methods combining multiple IntervalCombinable
.Interval
s
Nothing
Data Types
An
is a pair of Interval
aa
s \( (x, y) \text{ where } x < y\). The
class provides a safe Intervallic
function that returns a
parseInterval
error if \(y < x\) and Left
unsafeInterval
as constructor for creating an
interval that may not be valid.
Interval (a, a) |
Instances
Eq a => Eq (Interval a) Source # | |
Intervallic a => Ord (Interval a) Source # | Imposes a total ordering on |
(Intervallic a, Show a) => Show (Interval a) Source # | |
data IntervalRelation Source #
The IntervalRelation
type enumerates the thirteen possible ways that two
objects can relate according to the interval algebra.Interval
a
Meets, Metby
x `meets` y y `metBy` x
x: |-----| y: |-----|
Before, After
x `before` y y `after` x
x: |-----| y: |-----|
Overlaps, OverlappedBy
x `overlaps` y y `overlappedBy` x
x: |-----| y: |-----|
Starts, StartedBy
x `starts` y y `startedBy` x
x: |---| y: |-----|
Finishes, FinishedBy
x `finishes` y y `finishedBy` x
x: |---| y: |-----|
During, Contains
x `during` y y `contains` x
x: |-| y: |-----|
Equal
x `equal` y y `equal` x
x: |-----| y: |-----|
Instances
Read IntervalRelation Source # | |
Defined in IntervalAlgebra | |
Show IntervalRelation Source # | |
Defined in IntervalAlgebra showsPrec :: Int -> IntervalRelation -> ShowS # show :: IntervalRelation -> String # showList :: [IntervalRelation] -> ShowS # |
type ComparativePredicateOf a = a -> a -> Bool Source #
Defines a predicate of two objects of type a
.