Deprecated

In favour of

numhask-range

Numbers that are range representations

https://github.com/tonyday567/numhask-range

Version on this page:0.1.1
LTS Haskell 12.26:0.2.3.1
Stackage Nightly 2018-09-28:0.2.3.1
Latest on Hackage:0.2.3.1

See all snapshots numhask-range appears in

BSD-3-Clause licensed by Tony Day
Maintained by [email protected]
This version can be pinned in stack with:numhask-range-0.1.1@sha256:6e07706080f6232f95fa3cacd6b199c7766826b2fec614a69843cb8447a1af7b,1706

Module documentation for 0.1.1

numhask-range

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 what you find:

other/unitSquare.svg

To a first approximation, charting is transforming unit squares and placing them 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.