chart-svg-0.6.0.0: Charting library targetting SVGs.
Safe HaskellSafe-Inferred
LanguageGHC2021

Chart.Data

Description

Data primitives and utilities

Whilst the library makes use of numhask, it does not re-export, to avoid clashes with Prelude, with the exception of zero, one, angle & abs.

Rect and Point, from numhask-space, make up the base elements of many chart primitives.

Synopsis

Data Primitives

newtype Rect a #

a rectangular space often representing a finite 2-dimensional or XY plane.

>>> one :: Rect Double
Rect (-0.5) 0.5 (-0.5) 0.5
>>> zero :: Rect Double
Rect 0.0 0.0 0.0 0.0
>>> one + one :: Rect Double
Rect (-1.0) 1.0 (-1.0) 1.0
>>> let a = Rect (-1.0) 1.0 (-2.0) 4.0
>>> a
Rect (-1.0) 1.0 (-2.0) 4.0
>>> a * one
Rect (-1.0) 1.0 (-2.0) 4.0
>>> let (Ranges x y) = a
>>> x
Range -1.0 1.0
>>> y
Range -2.0 4.0
>>> fmap (+1) (Rect 1 2 3 4)
Rect 2 3 4 5

as a Space instance with Points as Elements

>>> project (Rect 0.0 1.0 (-1.0) 0.0) (Rect 1.0 4.0 10.0 0.0) (Point 0.5 1.0)
Point 2.5 (-10.0)
>>> gridSpace (Rect 0.0 10.0 0.0 1.0) (Point (2::Int) (2::Int))
[Rect 0.0 5.0 0.0 0.5,Rect 0.0 5.0 0.5 1.0,Rect 5.0 10.0 0.0 0.5,Rect 5.0 10.0 0.5 1.0]
>>> grid MidPos (Rect 0.0 10.0 0.0 1.0) (Point (2::Int) (2::Int))
[Point 2.5 0.25,Point 2.5 0.75,Point 7.5 0.25,Point 7.5 0.75]

Constructors

Rect' (Compose Point Range a) 

Instances

Instances details
Representable Rect 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Rep Rect #

Methods

tabulate :: (Rep Rect -> a) -> Rect a #

index :: Rect a -> Rep Rect -> a #

Foldable Rect 
Instance details

Defined in NumHask.Space.Rect

Methods

fold :: Monoid m => Rect m -> m #

foldMap :: Monoid m => (a -> m) -> Rect a -> m #

foldMap' :: Monoid m => (a -> m) -> Rect a -> m #

foldr :: (a -> b -> b) -> b -> Rect a -> b #

foldr' :: (a -> b -> b) -> b -> Rect a -> b #

foldl :: (b -> a -> b) -> b -> Rect a -> b #

foldl' :: (b -> a -> b) -> b -> Rect a -> b #

foldr1 :: (a -> a -> a) -> Rect a -> a #

foldl1 :: (a -> a -> a) -> Rect a -> a #

toList :: Rect a -> [a] #

null :: Rect a -> Bool #

length :: Rect a -> Int #

elem :: Eq a => a -> Rect a -> Bool #

maximum :: Ord a => Rect a -> a #

minimum :: Ord a => Rect a -> a #

sum :: Num a => Rect a -> a #

product :: Num a => Rect a -> a #

Traversable Rect 
Instance details

Defined in NumHask.Space.Rect

Methods

traverse :: Applicative f => (a -> f b) -> Rect a -> f (Rect b) #

sequenceA :: Applicative f => Rect (f a) -> f (Rect a) #

mapM :: Monad m => (a -> m b) -> Rect a -> m (Rect b) #

sequence :: Monad m => Rect (m a) -> m (Rect a) #

Applicative Rect 
Instance details

Defined in NumHask.Space.Rect

Methods

pure :: a -> Rect a #

(<*>) :: Rect (a -> b) -> Rect a -> Rect b #

liftA2 :: (a -> b -> c) -> Rect a -> Rect b -> Rect c #

(*>) :: Rect a -> Rect b -> Rect b #

(<*) :: Rect a -> Rect b -> Rect a #

Functor Rect 
Instance details

Defined in NumHask.Space.Rect

Methods

fmap :: (a -> b) -> Rect a -> Rect b #

(<$) :: a -> Rect b -> Rect a #

Distributive Rect 
Instance details

Defined in NumHask.Space.Rect

Methods

distribute :: Functor f => f (Rect a) -> Rect (f a) #

collect :: Functor f => (a -> Rect b) -> f a -> Rect (f b) #

distributeM :: Monad m => m (Rect a) -> Rect (m a) #

collectM :: Monad m => (a -> Rect b) -> m a -> Rect (m b) #

Ord a => Semigroup (Rect a) 
Instance details

Defined in NumHask.Space.Rect

Methods

(<>) :: Rect a -> Rect a -> Rect a #

sconcat :: NonEmpty (Rect a) -> Rect a #

stimes :: Integral b => b -> Rect a -> Rect a #

Generic (Rect a) 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Rep (Rect a) :: Type -> Type #

Methods

from :: Rect a -> Rep (Rect a) x #

to :: Rep (Rect a) x -> Rect a #

(Ord a, Additive a, Show a) => Show (Rect a) 
Instance details

Defined in NumHask.Space.Rect

Methods

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

show :: Rect a -> String #

showList :: [Rect a] -> ShowS #

Eq a => Eq (Rect a) 
Instance details

Defined in NumHask.Space.Rect

Methods

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

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

Additive a => Additive (Rect a)

Numeric algebra based on interval arithmetic for addition and unitRect and projection for multiplication >>> one + one :: Rect Double Rect (-1.0) 1.0 (-1.0) 1.0

Instance details

Defined in NumHask.Space.Rect

Methods

(+) :: Rect a -> Rect a -> Rect a #

zero :: Rect a #

Subtractive a => Subtractive (Rect a) 
Instance details

Defined in NumHask.Space.Rect

Methods

negate :: Rect a -> Rect a #

(-) :: Rect a -> Rect a -> Rect a #

(Ord a, Field a) => Basis (Rect a) 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Mag (Rect a) #

type Base (Rect a) #

Methods

magnitude :: Rect a -> Mag (Rect a) #

basis :: Rect a -> Base (Rect a) #

(Ord a, Field a) => Divisive (Rect a) 
Instance details

Defined in NumHask.Space.Rect

Methods

recip :: Rect a -> Rect a #

(/) :: Rect a -> Rect a -> Rect a #

(Ord a, Field a) => Multiplicative (Rect a) 
Instance details

Defined in NumHask.Space.Rect

Methods

(*) :: Rect a -> Rect a -> Rect a #

one :: Rect a #

(FromIntegral a Int, Field a, Ord a) => FieldSpace (Rect a) 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Grid (Rect a) #

Methods

grid :: Pos -> Rect a -> Grid (Rect a) -> [Element (Rect a)] #

gridSpace :: Rect a -> Grid (Rect a) -> [Rect a] #

Ord a => Space (Rect a) 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Element (Rect a) #

Methods

lower :: Rect a -> Element (Rect a) #

upper :: Rect a -> Element (Rect a) #

singleton :: Element (Rect a) -> Rect a #

intersection :: Rect a -> Rect a -> Rect a #

union :: Rect a -> Rect a -> Rect a #

normalise :: Rect a -> Rect a #

(...) :: Element (Rect a) -> Element (Rect a) -> Rect a #

(>.<) :: Element (Rect a) -> Element (Rect a) -> Rect a #

(|.|) :: Element (Rect a) -> Rect a -> Bool #

(|>|) :: Rect a -> Rect a -> Bool #

(|<|) :: Rect a -> Rect a -> Bool #

type Rep Rect 
Instance details

Defined in NumHask.Space.Rect

type Rep Rect = (Bool, Bool)
type Rep (Rect a) 
Instance details

Defined in NumHask.Space.Rect

type Rep (Rect a) = D1 ('MetaData "Rect" "NumHask.Space.Rect" "numhask-space-0.11.1.0-2yB7UaP6U2YCAyhEBJ92Xh" 'True) (C1 ('MetaCons "Rect'" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Compose Point Range a))))
type Base (Rect a) 
Instance details

Defined in NumHask.Space.Rect

type Base (Rect a) = a
type Mag (Rect a) 
Instance details

Defined in NumHask.Space.Rect

type Mag (Rect a) = Rect a
type Element (Rect a) 
Instance details

Defined in NumHask.Space.Rect

type Element (Rect a) = Point a
type Grid (Rect a) 
Instance details

Defined in NumHask.Space.Rect

type Grid (Rect a) = Point Int

pattern Rect :: a -> a -> a -> a -> Rect a #

pattern of Rect lowerx upperx lowery uppery

mid :: (Space s, Field (Element s)) => s -> Element s #

middle element of the space

foldRect :: Ord a => [Rect a] -> Maybe (Rect a) #

convex hull union of Rect's

>>> foldRect [Rect 0 1 0 1, one]
Just Rect (-0.5) 1.0 (-0.5) 1.0

addPoint :: Additive a => Point a -> Rect a -> Rect a #

add a Point to a Rect

>>> addPoint (Point 0 1) one
Rect (-0.5) 0.5 0.5 1.5

projectOnP :: Rect Double -> Rect Double -> Point Double -> Point Double #

project a Point from one Rect to another, preserving relative position, with guards for singleton Rects.

>>> projectOnP one (Rect 0 1 0 1) zero
Point (-0.5) (-0.5)

projectOnR :: Rect Double -> Rect Double -> Rect Double -> Rect Double #

project a Rect from one Rect to another, preserving relative position, with guards for singleton Rects.

>>> projectOnR one (Rect 0 1 0 1) (Rect 0 0.5 0 0.5)
Rect (-0.5) 0.0 (-0.5) 0.0

space1 :: (Space s, Traversable f) => f (Element s) -> Maybe s #

Maybe containing space of a traversable.

padRect :: Subtractive a => a -> Rect a -> Rect a Source #

Additive pad (or frame or buffer) a Rect.

>>> padRect 1 one
Rect (-1.5) 1.5 (-1.5) 1.5

padSingletons :: Rect Double -> Rect Double Source #

Pad a Rect to remove singleton dimensions.

Attempting to scale a singleton dimension of a Rect is a common bug.

Due to the use of scaling, and thus zero dividing, this is a common exception to guard against.

>>> project (Rect 0 0 0 1) one (Point 0 0)
Point NaN (-0.5)
>>> project (padSingletons (Rect 0 0 0 1)) one (Point 0 0)
Point 0.0 (-0.5)

isSingleton :: Rect Double -> Bool Source #

is any dimension singular?

data Point a #

A 2-dimensional Point of a's

In contrast with a tuple, a Point is functorial over both arguments.

>>> let p = Point 1 1
>>> p + p
Point 2 2
>>> (2*) <$> p
Point 2 2

A major reason for this bespoke treatment (compared to just using linear, say) is that Points do not have maximums and minimums but they do form a lattice, and this is useful for folding sets of points to find out the (rectangular) Space they occupy.

>>> Point 0 1 /\ Point 1 0
Point 0 0
>>> Point 0 1 \/ Point 1 0
Point 1 1

This is used extensively in chart-svg to ergonomically obtain chart areas.

unsafeSpace1 [Point 1 0, Point 0 1] :: Rect Double

Rect 0.0 1.0 0.0 1.0

Constructors

Point 

Fields

Instances

Instances details
Representable Point 
Instance details

Defined in NumHask.Space.Point

Associated Types

type Rep Point #

Methods

tabulate :: (Rep Point -> a) -> Point a #

index :: Point a -> Rep Point -> a #

Foldable Point 
Instance details

Defined in NumHask.Space.Point

Methods

fold :: Monoid m => Point m -> m #

foldMap :: Monoid m => (a -> m) -> Point a -> m #

foldMap' :: Monoid m => (a -> m) -> Point a -> m #

foldr :: (a -> b -> b) -> b -> Point a -> b #

foldr' :: (a -> b -> b) -> b -> Point a -> b #

foldl :: (b -> a -> b) -> b -> Point a -> b #

foldl' :: (b -> a -> b) -> b -> Point a -> b #

foldr1 :: (a -> a -> a) -> Point a -> a #

foldl1 :: (a -> a -> a) -> Point a -> a #

toList :: Point a -> [a] #

null :: Point a -> Bool #

length :: Point a -> Int #

elem :: Eq a => a -> Point a -> Bool #

maximum :: Ord a => Point a -> a #

minimum :: Ord a => Point a -> a #

sum :: Num a => Point a -> a #

product :: Num a => Point a -> a #

Eq1 Point 
Instance details

Defined in NumHask.Space.Point

Methods

liftEq :: (a -> b -> Bool) -> Point a -> Point b -> Bool #

Traversable Point 
Instance details

Defined in NumHask.Space.Point

Methods

traverse :: Applicative f => (a -> f b) -> Point a -> f (Point b) #

sequenceA :: Applicative f => Point (f a) -> f (Point a) #

mapM :: Monad m => (a -> m b) -> Point a -> m (Point b) #

sequence :: Monad m => Point (m a) -> m (Point a) #

Applicative Point 
Instance details

Defined in NumHask.Space.Point

Methods

pure :: a -> Point a #

(<*>) :: Point (a -> b) -> Point a -> Point b #

liftA2 :: (a -> b -> c) -> Point a -> Point b -> Point c #

(*>) :: Point a -> Point b -> Point b #

(<*) :: Point a -> Point b -> Point a #

Functor Point 
Instance details

Defined in NumHask.Space.Point

Methods

fmap :: (a -> b) -> Point a -> Point b #

(<$) :: a -> Point b -> Point a #

Monad Point 
Instance details

Defined in NumHask.Space.Point

Methods

(>>=) :: Point a -> (a -> Point b) -> Point b #

(>>) :: Point a -> Point b -> Point b #

return :: a -> Point a #

Distributive Point 
Instance details

Defined in NumHask.Space.Point

Methods

distribute :: Functor f => f (Point a) -> Point (f a) #

collect :: Functor f => (a -> Point b) -> f a -> Point (f b) #

distributeM :: Monad m => m (Point a) -> Point (m a) #

collectM :: Monad m => (a -> Point b) -> m a -> Point (m b) #

Monoid a => Monoid (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

mempty :: Point a #

mappend :: Point a -> Point a -> Point a #

mconcat :: [Point a] -> Point a #

Semigroup a => Semigroup (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

(<>) :: Point a -> Point a -> Point a #

sconcat :: NonEmpty (Point a) -> Point a #

stimes :: Integral b => b -> Point a -> Point a #

Bounded a => Bounded (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

minBound :: Point a #

maxBound :: Point a #

Generic (Point a) 
Instance details

Defined in NumHask.Space.Point

Associated Types

type Rep (Point a) :: Type -> Type #

Methods

from :: Point a -> Rep (Point a) x #

to :: Rep (Point a) x -> Point a #

(Ord a, Additive a, Show a) => Show (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

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

show :: Point a -> String #

showList :: [Point a] -> ShowS #

Eq a => Eq (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

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

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

Additive a => AdditiveAction (Point a) 
Instance details

Defined in NumHask.Space.Point

Associated Types

type AdditiveScalar (Point a) #

Methods

(|+) :: Point a -> AdditiveScalar (Point a) -> Point a #

Divisive a => DivisiveAction (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

(|/) :: Point a -> Scalar (Point a) -> Point a #

Multiplicative a => MultiplicativeAction (Point a) 
Instance details

Defined in NumHask.Space.Point

Associated Types

type Scalar (Point a) #

Methods

(|*) :: Point a -> Scalar (Point a) -> Point a #

Subtractive a => SubtractiveAction (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

(|-) :: Point a -> AdditiveScalar (Point a) -> Point a #

Additive a => Additive (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

(+) :: Point a -> Point a -> Point a #

zero :: Point a #

Subtractive a => Subtractive (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

negate :: Point a -> Point a #

(-) :: Point a -> Point a -> Point a #

Ord a => JoinSemiLattice (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

(\/) :: Point a -> Point a -> Point a #

Ord a => MeetSemiLattice (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

(/\) :: Point a -> Point a -> Point a #

(ExpField a, Eq a) => Basis (Point a) 
Instance details

Defined in NumHask.Space.Point

Associated Types

type Mag (Point a) #

type Base (Point a) #

Methods

magnitude :: Point a -> Mag (Point a) #

basis :: Point a -> Base (Point a) #

TrigField a => Direction (Point a)

angle formed by a vector from the origin to a Point and the x-axis (Point 1 0). Note that an angle between two points p1 & p2 is thus angle p2 - angle p1

Instance details

Defined in NumHask.Space.Point

Associated Types

type Dir (Point a) #

Methods

angle :: Point a -> Dir (Point a) #

ray :: Dir (Point a) -> Point a #

Divisive a => Divisive (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

recip :: Point a -> Point a #

(/) :: Point a -> Point a -> Point a #

Multiplicative a => Multiplicative (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

(*) :: Point a -> Point a -> Point a #

one :: Point a #

UniformRange a => UniformRange (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

uniformRM :: StatefulGen g m => (Point a, Point a) -> g -> m (Point a) #

(Multiplicative a, Additive a) => Affinity (Point a) a 
Instance details

Defined in NumHask.Space.Point

Methods

transform :: Transform a -> Point a -> Point a #

type Rep Point 
Instance details

Defined in NumHask.Space.Point

type Rep Point = Bool
type Rep (Point a) 
Instance details

Defined in NumHask.Space.Point

type Rep (Point a) = D1 ('MetaData "Point" "NumHask.Space.Point" "numhask-space-0.11.1.0-2yB7UaP6U2YCAyhEBJ92Xh" 'False) (C1 ('MetaCons "Point" 'PrefixI 'True) (S1 ('MetaSel ('Just "_x") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "_y") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))
type AdditiveScalar (Point a) 
Instance details

Defined in NumHask.Space.Point

type AdditiveScalar (Point a) = a
type Scalar (Point a) 
Instance details

Defined in NumHask.Space.Point

type Scalar (Point a) = a
type Base (Point a) 
Instance details

Defined in NumHask.Space.Point

type Base (Point a) = Point a
type Dir (Point a) 
Instance details

Defined in NumHask.Space.Point

type Dir (Point a) = a
type Mag (Point a) 
Instance details

Defined in NumHask.Space.Point

type Mag (Point a) = a

addp :: Point Double -> Point Double -> Point Double Source #

add Points, dimension-wise

>>> Point 1 1 `addp` Point 0 2
Point 1.0 3.0

data Range a #

A continuous range over type a

>>> let a = Range (-1) 1
>>> a
Range -1 1
>>> a + a
Range -2 2
>>> a * a
Range -2.0 2.0
>>> (+1) <$> (Range 1 2)
Range 2 3

Ranges are very useful in shifting a bunch of numbers from one Range to another. eg project 0.5 from the range 0 to 1 to the range 1 to 4

>>> project (Range 0 1) (Range 1 4) 0.5
2.5

Create an equally spaced grid including outer bounds over a Range

>>> grid OuterPos (Range 0.0 10.0) 5
[0.0,2.0,4.0,6.0,8.0,10.0]

divide up a Range into equal-sized sections

>>> gridSpace (Range 0.0 1.0) 4
[Range 0.0 0.25,Range 0.25 0.5,Range 0.5 0.75,Range 0.75 1.0]

Constructors

Range a a 

Instances

Instances details
Representable Range 
Instance details

Defined in NumHask.Space.Range

Associated Types

type Rep Range #

Methods

tabulate :: (Rep Range -> a) -> Range a #

index :: Range a -> Rep Range -> a #

Foldable Range 
Instance details

Defined in NumHask.Space.Range

Methods

fold :: Monoid m => Range m -> m #

foldMap :: Monoid m => (a -> m) -> Range a -> m #

foldMap' :: Monoid m => (a -> m) -> Range a -> m #

foldr :: (a -> b -> b) -> b -> Range a -> b #

foldr' :: (a -> b -> b) -> b -> Range a -> b #

foldl :: (b -> a -> b) -> b -> Range a -> b #

foldl' :: (b -> a -> b) -> b -> Range a -> b #

foldr1 :: (a -> a -> a) -> Range a -> a #

foldl1 :: (a -> a -> a) -> Range a -> a #

toList :: Range a -> [a] #

null :: Range a -> Bool #

length :: Range a -> Int #

elem :: Eq a => a -> Range a -> Bool #

maximum :: Ord a => Range a -> a #

minimum :: Ord a => Range a -> a #

sum :: Num a => Range a -> a #

product :: Num a => Range a -> a #

Eq1 Range 
Instance details

Defined in NumHask.Space.Range

Methods

liftEq :: (a -> b -> Bool) -> Range a -> Range b -> Bool #

Traversable Range 
Instance details

Defined in NumHask.Space.Range

Methods

traverse :: Applicative f => (a -> f b) -> Range a -> f (Range b) #

sequenceA :: Applicative f => Range (f a) -> f (Range a) #

mapM :: Monad m => (a -> m b) -> Range a -> m (Range b) #

sequence :: Monad m => Range (m a) -> m (Range a) #

Applicative Range 
Instance details

Defined in NumHask.Space.Range

Methods

pure :: a -> Range a #

(<*>) :: Range (a -> b) -> Range a -> Range b #

liftA2 :: (a -> b -> c) -> Range a -> Range b -> Range c #

(*>) :: Range a -> Range b -> Range b #

(<*) :: Range a -> Range b -> Range a #

Functor Range 
Instance details

Defined in NumHask.Space.Range

Methods

fmap :: (a -> b) -> Range a -> Range b #

(<$) :: a -> Range b -> Range a #

Distributive Range 
Instance details

Defined in NumHask.Space.Range

Methods

distribute :: Functor f => f (Range a) -> Range (f a) #

collect :: Functor f => (a -> Range b) -> f a -> Range (f b) #

distributeM :: Monad m => m (Range a) -> Range (m a) #

collectM :: Monad m => (a -> Range b) -> m a -> Range (m b) #

Apply Range 
Instance details

Defined in NumHask.Space.Range

Methods

(<.>) :: Range (a -> b) -> Range a -> Range b #

(.>) :: Range a -> Range b -> Range b #

(<.) :: Range a -> Range b -> Range a #

liftF2 :: (a -> b -> c) -> Range a -> Range b -> Range c #

Ord a => Semigroup (Range a)

Monoid based on convex hull union

Instance details

Defined in NumHask.Space.Range

Methods

(<>) :: Range a -> Range a -> Range a #

sconcat :: NonEmpty (Range a) -> Range a #

stimes :: Integral b => b -> Range a -> Range a #

Generic (Range a) 
Instance details

Defined in NumHask.Space.Range

Associated Types

type Rep (Range a) :: Type -> Type #

Methods

from :: Range a -> Rep (Range a) x #

to :: Rep (Range a) x -> Range a #

Show a => Show (Range a) 
Instance details

Defined in NumHask.Space.Range

Methods

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

show :: Range a -> String #

showList :: [Range a] -> ShowS #

Eq a => Eq (Range a) 
Instance details

Defined in NumHask.Space.Range

Methods

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

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

(Additive a, Ord a) => Additive (Range a) 
Instance details

Defined in NumHask.Space.Range

Methods

(+) :: Range a -> Range a -> Range a #

zero :: Range a #

(Subtractive a, Ord a) => Subtractive (Range a) 
Instance details

Defined in NumHask.Space.Range

Methods

negate :: Range a -> Range a #

(-) :: Range a -> Range a -> Range a #

Ord a => JoinSemiLattice (Range a) 
Instance details

Defined in NumHask.Space.Range

Methods

(\/) :: Range a -> Range a -> Range a #

Ord a => MeetSemiLattice (Range a) 
Instance details

Defined in NumHask.Space.Range

Methods

(/\) :: Range a -> Range a -> Range a #

(Field a, Ord a) => Basis (Range a) 
Instance details

Defined in NumHask.Space.Range

Associated Types

type Mag (Range a) #

type Base (Range a) #

Methods

magnitude :: Range a -> Mag (Range a) #

basis :: Range a -> Base (Range a) #

(Ord a, Field a) => Divisive (Range a) 
Instance details

Defined in NumHask.Space.Range

Methods

recip :: Range a -> Range a #

(/) :: Range a -> Range a -> Range a #

(Field a, Ord a) => Multiplicative (Range a) 
Instance details

Defined in NumHask.Space.Range

Methods

(*) :: Range a -> Range a -> Range a #

one :: Range a #

(Field a, Ord a, FromIntegral a Int) => FieldSpace (Range a) 
Instance details

Defined in NumHask.Space.Range

Associated Types

type Grid (Range a) #

Methods

grid :: Pos -> Range a -> Grid (Range a) -> [Element (Range a)] #

gridSpace :: Range a -> Grid (Range a) -> [Range a] #

Ord a => Space (Range a) 
Instance details

Defined in NumHask.Space.Range

Associated Types

type Element (Range a) #

Methods

lower :: Range a -> Element (Range a) #

upper :: Range a -> Element (Range a) #

singleton :: Element (Range a) -> Range a #

intersection :: Range a -> Range a -> Range a #

union :: Range a -> Range a -> Range a #

normalise :: Range a -> Range a #

(...) :: Element (Range a) -> Element (Range a) -> Range a #

(>.<) :: Element (Range a) -> Element (Range a) -> Range a #

(|.|) :: Element (Range a) -> Range a -> Bool #

(|>|) :: Range a -> Range a -> Bool #

(|<|) :: Range a -> Range a -> Bool #

type Rep Range 
Instance details

Defined in NumHask.Space.Range

type Rep Range = Bool
type Rep (Range a) 
Instance details

Defined in NumHask.Space.Range

type Rep (Range a) = D1 ('MetaData "Range" "NumHask.Space.Range" "numhask-space-0.11.1.0-2yB7UaP6U2YCAyhEBJ92Xh" 'False) (C1 ('MetaCons "Range" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))
type Base (Range a) 
Instance details

Defined in NumHask.Space.Range

type Base (Range a) = a
type Mag (Range a) 
Instance details

Defined in NumHask.Space.Range

type Mag (Range a) = Range a
type Element (Range a) 
Instance details

Defined in NumHask.Space.Range

type Element (Range a) = a
type Grid (Range a) 
Instance details

Defined in NumHask.Space.Range

type Grid (Range a) = Int

NumHask Exports

class Multiplicative a where #

or Multiplication

For practical reasons, we begin the class tree with Additive and Multiplicative. Starting with Associative and Unital, or using Semigroup and Monoid from base tends to confuse the interface once you start having to disinguish between (say) monoidal addition and monoidal multiplication.

\a -> one * a == a
\a -> a * one == a
\a b c -> (a * b) * c == a * (b * c)

By convention, (*) is regarded as not necessarily commutative, but this is not universal, and the introduction of another symbol which means commutative multiplication seems a bit dogmatic.

>>> one * 2
2
>>> 2 * 3
6

Minimal complete definition

(*), one

Methods

one :: a #

Instances

Instances details
Multiplicative Int16 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Int16 -> Int16 -> Int16 #

one :: Int16 #

Multiplicative Int32 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Int32 -> Int32 -> Int32 #

one :: Int32 #

Multiplicative Int64 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Int64 -> Int64 -> Int64 #

one :: Int64 #

Multiplicative Int8 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Int8 -> Int8 -> Int8 #

one :: Int8 #

Multiplicative Word16 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Word16 -> Word16 -> Word16 #

one :: Word16 #

Multiplicative Word32 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Word32 -> Word32 -> Word32 #

one :: Word32 #

Multiplicative Word64 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Word64 -> Word64 -> Word64 #

one :: Word64 #

Multiplicative Word8 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Word8 -> Word8 -> Word8 #

one :: Word8 #

Multiplicative Integer 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Integer -> Integer -> Integer #

one :: Integer #

Multiplicative Natural 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Natural -> Natural -> Natural #

one :: Natural #

Multiplicative Bool 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Bool -> Bool -> Bool #

one :: Bool #

Multiplicative Double 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Double -> Double -> Double #

one :: Double #

Multiplicative Float 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Float -> Float -> Float #

one :: Float #

Multiplicative Int 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Int -> Int -> Int #

one :: Int #

Multiplicative Word 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: Word -> Word -> Word #

one :: Word #

Multiplicative a => Multiplicative (EuclideanPair a) 
Instance details

Defined in NumHask.Algebra.Metric

(Subtractive a, Multiplicative a) => Multiplicative (Complex a) 
Instance details

Defined in NumHask.Data.Complex

Methods

(*) :: Complex a -> Complex a -> Complex a #

one :: Complex a #

(Ord a, EndoBased a, Integral a, Ring a) => Multiplicative (Ratio a) 
Instance details

Defined in NumHask.Data.Rational

Methods

(*) :: Ratio a -> Ratio a -> Ratio a #

one :: Ratio a #

Multiplicative a => Multiplicative (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

(*) :: Point a -> Point a -> Point a #

one :: Point a #

(Field a, Ord a) => Multiplicative (Range a) 
Instance details

Defined in NumHask.Space.Range

Methods

(*) :: Range a -> Range a -> Range a #

one :: Range a #

(Ord a, Field a) => Multiplicative (Rect a) 
Instance details

Defined in NumHask.Space.Rect

Methods

(*) :: Rect a -> Rect a -> Rect a #

one :: Rect a #

Multiplicative b => Multiplicative (a -> b) 
Instance details

Defined in NumHask.Algebra.Multiplicative

Methods

(*) :: (a -> b) -> (a -> b) -> a -> b #

one :: a -> b #

(Multiplicative a, Distributive a, Subtractive a, KnownNat m, HasShape '[m, m]) => Multiplicative (Matrix m m a) 
Instance details

Defined in NumHask.Array.Fixed

Methods

(*) :: Matrix m m a -> Matrix m m a -> Matrix m m a #

one :: Matrix m m a #

class Additive a where #

or Addition

For practical reasons, we begin the class tree with Additive. Starting with Associative and Unital, or using Semigroup and Monoid from base tends to confuse the interface once you start having to disinguish between (say) monoidal addition and monoidal multiplication.

\a -> zero + a == a
\a -> a + zero == a
\a b c -> (a + b) + c == a + (b + c)
\a b -> a + b == b + a

By convention, (+) is regarded as commutative, but this is not universal, and the introduction of another symbol which means non-commutative addition seems a bit dogmatic.

>>> zero + 1
1
>>> 1 + 1
2

Minimal complete definition

(+), zero

Methods

zero :: a #

Instances

Instances details
Additive Int16 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Int16 -> Int16 -> Int16 #

zero :: Int16 #

Additive Int32 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Int32 -> Int32 -> Int32 #

zero :: Int32 #

Additive Int64 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Int64 -> Int64 -> Int64 #

zero :: Int64 #

Additive Int8 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Int8 -> Int8 -> Int8 #

zero :: Int8 #

Additive Word16 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Word16 -> Word16 -> Word16 #

zero :: Word16 #

Additive Word32 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Word32 -> Word32 -> Word32 #

zero :: Word32 #

Additive Word64 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Word64 -> Word64 -> Word64 #

zero :: Word64 #

Additive Word8 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Word8 -> Word8 -> Word8 #

zero :: Word8 #

Additive Integer 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Integer -> Integer -> Integer #

zero :: Integer #

Additive Natural 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Natural -> Natural -> Natural #

zero :: Natural #

Additive Bool 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Bool -> Bool -> Bool #

zero :: Bool #

Additive Double 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Double -> Double -> Double #

zero :: Double #

Additive Float 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Float -> Float -> Float #

zero :: Float #

Additive Int 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Int -> Int -> Int #

zero :: Int #

Additive Word 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Word -> Word -> Word #

zero :: Word #

Additive a => Additive (Sum a) 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Sum a -> Sum a -> Sum a #

zero :: Sum a #

Additive a => Additive (EuclideanPair a) 
Instance details

Defined in NumHask.Algebra.Metric

Additive a => Additive (Complex a) 
Instance details

Defined in NumHask.Data.Complex

Methods

(+) :: Complex a -> Complex a -> Complex a #

zero :: Complex a #

(Ord a, EndoBased a, Integral a, Ring a) => Additive (Ratio a) 
Instance details

Defined in NumHask.Data.Rational

Methods

(+) :: Ratio a -> Ratio a -> Ratio a #

zero :: Ratio a #

Additive a => Additive (Point a) 
Instance details

Defined in NumHask.Space.Point

Methods

(+) :: Point a -> Point a -> Point a #

zero :: Point a #

(Additive a, Ord a) => Additive (Range a) 
Instance details

Defined in NumHask.Space.Range

Methods

(+) :: Range a -> Range a -> Range a #

zero :: Range a #

Additive a => Additive (Rect a)

Numeric algebra based on interval arithmetic for addition and unitRect and projection for multiplication >>> one + one :: Rect Double Rect (-1.0) 1.0 (-1.0) 1.0

Instance details

Defined in NumHask.Space.Rect

Methods

(+) :: Rect a -> Rect a -> Rect a #

zero :: Rect a #

Additive b => Additive (a -> b) 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: (a -> b) -> (a -> b) -> a -> b #

zero :: a -> b #

(Additive a, HasShape s) => Additive (Array s a) 
Instance details

Defined in NumHask.Array.Fixed

Methods

(+) :: Array s a -> Array s a -> Array s a #

zero :: Array s a #

abs :: Absolute a => a -> a #

The absolute value of a number.

\a -> abs a * signum a ~= a
>>> abs (-1)
1

class (Distributive coord, Distributive (Dir coord)) => Direction coord where #

Convert between a "co-ordinated" or "higher-kinded" number and a direction.

ray . angle == basis
magnitude (ray x) == one

Associated Types

type Dir coord #

Methods

angle :: coord -> Dir coord #

ray :: Dir coord -> coord #

Instances

Instances details
TrigField a => Direction (EuclideanPair a) 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Dir (EuclideanPair a) #

TrigField a => Direction (Complex a) 
Instance details

Defined in NumHask.Data.Complex

Associated Types

type Dir (Complex a) #

Methods

angle :: Complex a -> Dir (Complex a) #

ray :: Dir (Complex a) -> Complex a #

TrigField a => Direction (Point a)

angle formed by a vector from the origin to a Point and the x-axis (Point 1 0). Note that an angle between two points p1 & p2 is thus angle p2 - angle p1

Instance details

Defined in NumHask.Space.Point

Associated Types

type Dir (Point a) #

Methods

angle :: Point a -> Dir (Point a) #

ray :: Dir (Point a) -> Point a #

class Distributive (Mag a) => Basis a where #

Basis encapsulates the notion of magnitude (intuitively the quotienting of a higher-kinded number to a scalar one) and the basis on which the magnitude quotienting was performed. An instance needs to satisfy these laws:

\a -> magnitude a >= zero
\a -> magnitude zero == zero
\a -> a == magnitude a *| basis a
\a -> magnitude (basis a) == one

The names chosen are meant to represent the spiritual idea of a basis rather than a specific mathematics. See https://en.wikipedia.org/wiki/Basis_(linear_algebra) & https://en.wikipedia.org/wiki/Norm_(mathematics) for some mathematical motivations.

>>> magnitude (-0.5 :: Double)
0.5
>>> basis (-0.5 :: Double)
-1.0

Associated Types

type Mag a #

type Base a #

Methods

magnitude :: a -> Mag a #

or length, or ||v||

basis :: a -> Base a #

or direction, or v-hat

Instances

Instances details
Basis Int16 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Int16 #

type Base Int16 #

Basis Int32 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Int32 #

type Base Int32 #

Basis Int64 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Int64 #

type Base Int64 #

Basis Int8 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Int8 #

type Base Int8 #

Methods

magnitude :: Int8 -> Mag Int8 #

basis :: Int8 -> Base Int8 #

Basis Word16 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Word16 #

type Base Word16 #

Basis Word32 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Word32 #

type Base Word32 #

Basis Word64 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Word64 #

type Base Word64 #

Basis Word8 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Word8 #

type Base Word8 #

Basis Integer 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Integer #

type Base Integer #

Basis Natural 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Natural #

type Base Natural #

Basis Double 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Double #

type Base Double #

Basis Float 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Float #

type Base Float #

Basis Int 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Int #

type Base Int #

Methods

magnitude :: Int -> Mag Int #

basis :: Int -> Base Int #

Basis Word 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Word #

type Base Word #

Methods

magnitude :: Word -> Mag Word #

basis :: Word -> Base Word #

(ExpField a, Eq a) => Basis (EuclideanPair a) 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag (EuclideanPair a) #

type Base (EuclideanPair a) #

(Additive a, Multiplicative a) => Basis (Polar a) 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag (Polar a) #

type Base (Polar a) #

Methods

magnitude :: Polar a -> Mag (Polar a) #

basis :: Polar a -> Base (Polar a) #

(ExpField a, Eq a) => Basis (Complex a) 
Instance details

Defined in NumHask.Data.Complex

Associated Types

type Mag (Complex a) #

type Base (Complex a) #

Methods

magnitude :: Complex a -> Mag (Complex a) #

basis :: Complex a -> Base (Complex a) #

(Ord a, EndoBased a, Integral a, Ring a) => Basis (Ratio a) 
Instance details

Defined in NumHask.Data.Rational

Associated Types

type Mag (Ratio a) #

type Base (Ratio a) #

Methods

magnitude :: Ratio a -> Mag (Ratio a) #

basis :: Ratio a -> Base (Ratio a) #

(ExpField a, Eq a) => Basis (Point a) 
Instance details

Defined in NumHask.Space.Point

Associated Types

type Mag (Point a) #

type Base (Point a) #

Methods

magnitude :: Point a -> Mag (Point a) #

basis :: Point a -> Base (Point a) #

(Field a, Ord a) => Basis (Range a) 
Instance details

Defined in NumHask.Space.Range

Associated Types

type Mag (Range a) #

type Base (Range a) #

Methods

magnitude :: Range a -> Mag (Range a) #

basis :: Range a -> Base (Range a) #

(Ord a, Field a) => Basis (Rect a) 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Mag (Rect a) #

type Base (Rect a) #

Methods

magnitude :: Rect a -> Mag (Rect a) #

basis :: Rect a -> Base (Rect a) #