Safe Haskell | None |
---|---|
Language | Haskell2010 |
'Range -0.5 0.5 :: Range Double' is a 1-dimensional instance of a 'Space Double' from -0.5 to 0.5 on the Double number line.
The instances chosen for Range
are conducive to Charting. Specifically:
- a Range is polymorphic, with the main constraint being 'Ord a'
Additive
andMultiplicative
instances define numeric manipulation rather than relying on theNum
class in base.- '(+)' and '(<>)' are defined as the convex hull of two ranges (compare the interval package approach for + of `fmap (+)`).
zero
andmempty
are defined as `Range infinity neginfinity`. This arrangement targets a neat definition for conversion of a foldable into a range via a very neat `foldMap singleton`. An additional benefit is that Ranges are additively idempotent (a + a = a). - The starting point for understanding Range multiplication is the diagrams unitSquare. Restricting consideration to one-dimension, a natural
one
Range is `Range -0.5 0.5`, which uniquely satisfies the equations:
`mid one == zero` `width one == one`
where the right zero and one refer to the underlying type.
- newtype Range a = Range' (a, a)
- pattern Range :: forall a. a -> a -> Range a
- gridSensible :: (Fractional a, Ord a, FromInteger a, QuotientField a, ExpField a) => Pos -> Range a -> Int -> [a]
Documentation
Range is a newtype wrapped (a,a) tuple
Range' (a, a) |
pattern Range :: forall a. a -> a -> Range a Source #
A tuple is the preferred concrete implementation of a Range, due to many libraries having substantial optimizations for tuples already (eg Vector
). 'Pattern Synonyms' allow us to recover a constructor without the need for tuple syntax.
>>> Range 0 1
Range 0 1
gridSensible :: (Fractional a, Ord a, FromInteger a, QuotientField a, ExpField a) => Pos -> Range a -> Int -> [a] Source #
turn a range into n a
s pleasing to human sense and sensibility
the a
s may well lie outside the original range as a result