# numhask-range: Numbers that are range representations

[ bsd3, deprecated, library, project ] [ Propose Tags ]

Numbers that represent ranges of all sorts.

## Modules

#### Maintainer's Corner

For package maintainers and hackage trustees

Candidates

• 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, 0.1.3.0, 0.2.0.0, 0.2.1.0, 0.2.2.0, 0.2.2.1, 0.2.3.1 adjunctions, base (>=4.7 && <4.12), distributive, numhask-prelude (>=0.0.1.0), protolude, QuickCheck, semigroupoids [details] BSD-3-Clause Tony Day Tony Day tonyday567@gmail.com project https://github.com/tonyday567/numhask-range#readme https://github.com/tonyday567/numhask-range/issues head: git clone https://github.com/tonyday567/numhask-range by tonyday567 at 2018-04-07T01:59:44Z NixOS:0.2.3.1 7116 total (14 in the last 30 days) (no votes yet) [estimated by Bayesian average] λ λ λ Docs not available All reported builds failed as of 2021-06-02

[back to package description]

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.

## one

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


## zero

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.

## space

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.