interval-algebra-0.1.2: An implementation of Allen's interval algebra for temporal logic

Copyright(c) NoviSci Inc 2020
LicenseBSD3
Maintainerbsaul@novisci.com
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell2010

IntervalAlgebra

Contents

Description

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 Intervals:

  1. Intervallic provides an interface to the data structure of an Interval, defining how an Interval a is constructed.
  2. IntervalAlgebraic provides an interface to the IntervalRelations, the workhorse of Allen's temporal logic.
  3. IntervalCombinable provides an interface to methods of combining multiple Intervals.

An advantage of nested typeclass design is that developers can define an Interval of type a with just the amount of structure that they need.

Total Ordering of Intervals

The modules makes the (opinionated) choice of a total ordering for Intervallic Intervals. Namely, the ordering is based on first ordering the begins then the ends.

Development

This module is under development and the API may change in the future.

Synopsis

Classes

class (Ord a, Show a) => Intervallic a where Source #

The Intervallic typeclass specifies how an Interval as is constructed. It also includes functions for getting the begin and end of an Interval a.

Minimal complete definition

Nothing

Methods

parseInterval :: a -> a -> Either String (Interval a) Source #

Safely parse a pair of as to create an Interval a.

unsafeInterval :: a -> a -> Interval a Source #

Create a new Interval a. 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.

begin :: Interval a -> a Source #

Access the ends of an Interval a .

end :: Interval a -> a Source #

Access the ends of an Interval a .

class (Eq a, Intervallic a) => IntervalAlgebraic a where Source #

The IntervalAlgebraic 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 disjoint, in', and composeRelations.

Minimal complete definition

Nothing

Methods

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 ComparativePredicateOf Interval a.For example, composeRelations [before, meets] creates a predicate function determining if one interval is either before or meets another interval.

disjoint :: ComparativePredicateOf (Interval a) Source #

Are x and y disjoint (before, after, meets, or metBy)?

in' :: ComparativePredicateOf (Interval a) Source #

Is x contained in y in any sense (during, starts, finishes or equals?

Instances
IntervalAlgebraic Int Source # 
Instance details

Defined in IntervalAlgebra

IntervalAlgebraic Integer Source # 
Instance details

Defined in IntervalAlgebra

IntervalAlgebraic Day Source # 
Instance details

Defined in IntervalAlgebra

class IntervalAlgebraic a => IntervalCombinable a where Source #

The IntervalCombinable typeclass provides methods combining multiple Intervals.

Minimal complete definition

Nothing

Methods

(.+.) :: Interval a -> Interval a -> Maybe (Interval a) Source #

Maybe form a new Interval by the union of two Intervals that meet.

Data Types

newtype Interval a Source #

An Interval a is a pair of as \( (x, y) \text{ where } x < y\). The Intervallic class provides a safe parseInterval function that returns a Left error if \(y < x\) and unsafeInterval as constructor for creating an interval that may not be valid.

Constructors

Interval (a, a) 
Instances
Eq a => Eq (Interval a) Source # 
Instance details

Defined in IntervalAlgebra

Methods

(==) :: Interval a -> Interval a -> Bool #

(/=) :: Interval a -> Interval a -> Bool #

Intervallic a => Ord (Interval a) Source #

Imposes a total ordering on Interval a based on first ordering the begins then the ends.

Instance details

Defined in IntervalAlgebra

Methods

compare :: Interval a -> Interval a -> Ordering #

(<) :: Interval a -> Interval a -> Bool #

(<=) :: Interval a -> Interval a -> Bool #

(>) :: Interval a -> Interval a -> Bool #

(>=) :: Interval a -> Interval a -> Bool #

max :: Interval a -> Interval a -> Interval a #

min :: Interval a -> Interval a -> Interval a #

(Intervallic a, Show a) => Show (Interval a) Source # 
Instance details

Defined in IntervalAlgebra

Methods

showsPrec :: Int -> Interval a -> ShowS #

show :: Interval a -> String #

showList :: [Interval a] -> ShowS #

data IntervalRelation Source #

The IntervalRelation type enumerates the thirteen possible ways that two Interval a objects can relate according to the interval algebra.

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: |-----|

type ComparativePredicateOf a = a -> a -> Bool Source #

Defines a predicate of two objects of type a.