numhask-range: Numbers that are range representations

[ bsd3, deprecated, library, project ] [ Propose Tags ]
Deprecated in favor of numhask-space

Numbers that represent ranges of all sorts.

[Skip to Readme]


[Last Documentation]

  • NumHask
    • NumHask.Pair
    • NumHask.Range
    • NumHask.RangeD
    • NumHask.Rect
    • NumHask.Space


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS] 0.0.1, 0.0.2, 0.0.3, 0.0.4, 0.1.0, 0.1.1, 0.1.2,,,,,,
Dependencies adjunctions, base (>=4.7 && <4.12), distributive, numhask-prelude (>=, protolude, QuickCheck, semigroupoids [details]
License BSD-3-Clause
Copyright Tony Day
Author Tony Day
Category project
Home page
Bug tracker
Source repo head: git clone
Uploaded by tonyday567 at 2018-04-07T01:59:44Z
Reverse Dependencies 2 direct, 1 indirect [details]
Downloads 7450 total (13 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2021-06-02 [all 2 reports]

Readme for numhask-range-

[back to package description]


Build Status Hackage lts nightly

A Space represents an interval over a type. The main instance of a Space, a Range, consists of a lower and upper value, though lower > upper is allowed, and leads to a useful definition of a negative space. A Rect is a wrapped Compose Pair Range and so a two-dimensional Space.

spatial zeros and ones

This library emerged as a bridge between chart-unit, an effort to create a clean, minimalist chart api, and numhask, an effort to create clean, minimalist numerical classes.

If you ask yourself what a chart is, sifting through the cruft of accumulated practice, nomenclature and usage, digging deep for charting's essence, and if you ask the question in haskell, here's the simplest object you find:


To a first approximation, charting is transforming and placing this unit on a physical XY plane, such as a screen, or on graph paper. A rectangle is a distended square; a line is a very thin rectangle; a histogram is a series of rectangles, and axes are nothing more than a collection of squares. The main thing on a chart that isn't a square is text, but even then we use square pixels to render.


As a well-meaning, but eternally confused student of category theory, I had learnt to pay attention to the simplest thing I could find within a problem domain. To quote from the haddock, a unitSquare is "a square with its center at the origin and sides of length 1, oriented parallel to the axes." When we first learn to chart, the origin of a graph is usually at the bottom left, and only moves to the center once we learn our negative numbers. The origin for html/svg/css is at top left, however, and the y-axis heads down not up. So what makes this co-ordinate system the right one?

Reducing down to the one dimension case, the diagrams unit boils down to a range along a dimension of -0.5 to 0.5, or Range -0.5 0.5. Length is 1 and the mid-point is 0, so if we define Range -0.5 0.5 as one, the multiplicative unit, we get the very neat:

mid one == zero
width one == one

which absolutely nails the correct co-ordinate system, once you see how it easily it can extend to the two-dimensional case:

mid (one :: Rect a) == zero :: Pair a
width (one :: Rect a) == one :: Pair a


As a card carrying member of the + and <> should be the same thing committee, I gravitated towards a monoidally additive definition:

zero = Range infinity neginfinity
(+) (Range l u) (Range l' u') = Range (min l l') (max u u')
(<>) = (+)
mempty = zero

Known as a convex hull union, this operation is the bread-and-butter of charting. If you have an object at Range 2 3 and one at Range 0 1, then you're going to have to draw over Range 0 3 to get it all on the page.

It's very similar to a tropical semiring, which sets infinity as zero, min as +, and + as , often summarised as (infinity,min,+) versus the usual (0,+,) semiring. Reading up on star-semirings here, I suspect that an operation that doesn't fill in the holes, that remembers contiguous and non-contiguous intervals in a space, will complete this mempty and plus definition to form a star-semiring. But the unification of charting and regular expressions is another tale.


If spatial one and zero are the inspiration of the library, then NumHask.Space is the perspiration. The Space class are all the various bits and bobs that made up earlier versions of chart operations, refactored a hundred times and slowly reduced to a managable and coherent class.

The Space class came out of common functionality between Range and Rect. If current trends continue, Space will consume the remaining components of the Range class. To effect this, however, requires the number heirarchy to be defined for the Space class, which currently leads to compiler whining about orphans, ambiguity and undecidables. It may be that the consumption of Range ideas will lead to the necessity of wrapping Space in a newtype and that wrapper name may best be Range. The grind continues.