HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulesdl2-2.5.6.1Haskell2010

SDL.Vect

SDL's vector representation.

By default, re-exports the Linear and Linear.Affine modules from the linear package. With the no-linear Cabal flag, instead exports a duplicate implementation of the V2, V3, V4 and Point types from SDL.Internal.Vect, which provides as many instances as possible for those types while avoiding any additional dependencies.

Contents
  1. Point
  2. Vectors
Synopsis
  • Packagesdl2-2.5.6.1
  • Exports210
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceVect.hs
value(#.) :: Coercible c b => (b -> c) -> (a -> b) -> a -> c
#
value(.#) :: Coercible b a => (b -> c) -> (a -> b) -> a -> c
#
value(!!*) :: (Functor m, Functor r, Num a) => m (r a) -> a -> m (r a)

Matrix-scalar product

Example1 expression
V2 (V2 1 2) (V2 3 4) !!* 5V2 (V2 5 10) (V2 15 20)
value(!*) :: (Functor m, Foldable r, Additive r, Num a) => m (r a) -> r a -> m a

Matrix * column vector

Example1 expression
V2 (V3 1 2 3) (V3 4 5 6) !* V3 7 8 9V2 50 122
value(!*!)
  1. :: (Functor m, Foldable t, Additive t, Additive n, Num a)
  2. => m (t a)
  3. -> t (n a)
  4. -> m (n a)

Matrix product. This can compute any combination of sparse and dense multiplication.

Example1 expression
V2 (V3 1 2 3) (V3 4 5 6) !*! V3 (V2 1 2) (V2 3 4) (V2 4 5)V2 (V2 19 25) (V2 43 58)
Example1 expression
V2 (IntMap.fromList [(1,2)]) (IntMap.fromList [(2,3)]) !*! IntMap.fromList [(1,V3 0 0 1), (2, V3 0 0 5)]V2 (V3 0 0 2) (V3 0 0 15)
value(!+!) :: (Additive m, Additive n, Num a) => m (n a) -> m (n a) -> m (n a)

Entry-wise matrix addition.

Example1 expression
V2 (V3 1 2 3) (V3 4 5 6) !+! V2 (V3 7 8 9) (V3 1 2 3)V2 (V3 8 10 12) (V3 5 7 9)
value(!-!) :: (Additive m, Additive n, Num a) => m (n a) -> m (n a) -> m (n a)

Entry-wise matrix subtraction.

Example1 expression
V2 (V3 1 2 3) (V3 4 5 6) !-! V2 (V3 7 8 9) (V3 1 2 3)V2 (V3 (-6) (-6) (-6)) (V3 3 3 3)
value(*!) :: (Num a, Foldable t, Additive f, Additive t) => t a -> t (f a) -> f a

Row vector * matrix

Example1 expression
V2 1 2 *! V2 (V3 3 4 5) (V3 6 7 8)V3 15 18 21
value(*!!) :: (Functor m, Functor r, Num a) => a -> m (r a) -> m (r a)

Scalar-matrix product

Example1 expression
5 *!! V2 (V2 1 2) (V2 3 4)V2 (V2 5 10) (V2 15 20)
valueadjoint :: (Functor m, Distributive n, Conjugate a) => m (n a) -> n (m a)

Hermitian conjugate or conjugate transpose

Example1 expression
adjoint (V2 (V2 (1 :+ 2) (3 :+ 4)) (V2 (5 :+ 6) (7 :+ 8)))V2 (V2 (1.0 :+ (-2.0)) (5.0 :+ (-6.0))) (V2 (3.0 :+ (-4.0)) (7.0 :+ (-8.0)))
valuecolumn
  1. :: Representable f
  2. => LensLike (Context a b) s t a b
  3. -> Lens (f s) (f t) (f a) (f b)

This is a generalization of inside to work over any corepresentable Functor.

column :: Representable f => Lens s t a b -> Lens (f s) (f t) (f a) (f b)

In practice it is used to access a column of a matrix.

Example1 expression
V2 (V3 1 2 3) (V3 4 5 6) ^._xV3 1 2 3
Example1 expression
V2 (V3 1 2 3) (V3 4 5 6) ^.column _xV2 1 4
valuedet22 :: Num a => M22 a -> a

2x2 matrix determinant.

Example1 expression
det22 (V2 (V2 a b) (V2 c d))a * d - b * c
valuedet33 :: Num a => M33 a -> a

3x3 matrix determinant.

Example1 expression
det33 (V3 (V3 a b c) (V3 d e f) (V3 g h i))a * (e * i - f * h) - d * (b * i - c * h) + g * (b * f - c * e)
valueidentity :: (Num a, Traversable t, Applicative t) => t (t a)

The identity matrix for any dimension vector.

Example2 expressions
identity :: M44 IntV4 (V4 1 0 0 0) (V4 0 1 0 0) (V4 0 0 1 0) (V4 0 0 0 1)identity :: V3 (V3 Int)V3 (V3 1 0 0) (V3 0 1 0) (V3 0 0 1)
valueinv22 :: Fractional a => M22 a -> M22 a

2x2 matrix inverse.

Example1 expression
inv22 $ V2 (V2 1 2) (V2 3 4)V2 (V2 (-2.0) 1.0) (V2 1.5 (-0.5))
valueinv33 :: Fractional a => M33 a -> M33 a

3x3 matrix inverse.

Example1 expression
inv33 $ V3 (V3 1 2 4) (V3 4 2 2) (V3 1 1 1)V3 (V3 0.0 0.5 (-1.0)) (V3 (-0.5) (-0.75) 3.5) (V3 0.5 0.25 (-1.5))
valuem33_to_m44 :: Num a => M33 a -> M44 a

Convert a 3x3 matrix to a 4x4 matrix extending it with 0's in the new row and column.

valuem43_to_m44 :: Num a => M43 a -> M44 a

Convert from a 4x3 matrix to a 4x4 matrix, extending it with the [ 0 0 0 1 ] column vector

valuefrustum
  1. :: Floating a
  2. => a

    Left

  3. -> a

    Right

  4. -> a

    Bottom

  5. -> a

    Top

  6. -> a

    Near

  7. -> a

    Far

  8. -> M44 a

Build a perspective matrix per the classic glFrustum arguments.

valueinfinitePerspective
  1. :: Floating a
  2. => a

    FOV (y direction, in radians)

  3. -> a

    Aspect Ratio

  4. -> a

    Near plane

  5. -> M44 a

Build a matrix for a symmetric perspective-view frustum with a far plane at infinite

valueinverseOrtho
  1. :: Fractional a
  2. => a

    Left

  3. -> a

    Right

  4. -> a

    Bottom

  5. -> a

    Top

  6. -> a

    Near

  7. -> a

    Far

  8. -> M44 a

Build an inverse orthographic perspective matrix from 6 clipping planes

valueortho
  1. :: Fractional a
  2. => a

    Left

  3. -> a

    Right

  4. -> a

    Bottom

  5. -> a

    Top

  6. -> a

    Near

  7. -> a

    Far

  8. -> M44 a

Build an orthographic perspective matrix from 6 clipping planes. This matrix takes the region delimited by these planes and maps it to normalized device coordinates between [-1,1]

This call is designed to mimic the parameters to the OpenGL glOrtho call, so it has a slightly strange convention: Notably: the near and far planes are negated.

Consequently:

ortho l r b t n f !* V4 l b (-n) 1 = V4 (-1) (-1) (-1) 1
ortho l r b t n f !* V4 r t (-f) 1 = V4 1 1 1 1

Examples:

Example1 expression
ortho 1 2 3 4 5 6 !* V4 1 3 (-5) 1V4 (-1.0) (-1.0) (-1.0) 1.0
Example1 expression
ortho 1 2 3 4 5 6 !* V4 2 4 (-6) 1V4 1.0 1.0 1.0 1.0
valueperspective
  1. :: Floating a
  2. => a

    FOV (y direction, in radians)

  3. -> a

    Aspect ratio

  4. -> a

    Near plane

  5. -> a

    Far plane

  6. -> M44 a

Build a matrix for a symmetric perspective-view frustum

valuecrossZ :: Num a => V2 a -> V2 a -> a

The Z-component of the cross product of two vectors in the XY-plane.

Example1 expression
crossZ (V2 1 0) (V2 0 1)1
valueperp :: Num a => V2 a -> V2 a

the counter-clockwise perpendicular vector

Example1 expression
perp $ V2 10 20V2 (-20) 10
valuenormalizePoint :: Fractional a => V4 a -> V3 a

Convert 4-dimensional projective coordinates to a 3-dimensional point. This operation may be denoted, euclidean [x:y:z:w] = (x/w, y/w, z/w) where the projective, homogenous, coordinate [x:y:z:w] is one of many associated with a single point (x/w, y/w, z/w).

valuepoint :: Num a => V3 a -> V4 a

Convert a 3-dimensional affine point into a 4-dimensional homogeneous vector, i.e. sets the w coordinate to 1.

valuevector :: Num a => V3 a -> V4 a

Convert a 3-dimensional affine vector into a 4-dimensional homogeneous vector, i.e. sets the w coordinate to 0.

value(*^) :: (Functor f, Num a) => a -> f a -> f a

Compute the left scalar product

Example1 expression
2 *^ V2 3 4V2 6 8
value(^*) :: (Functor f, Num a) => f a -> a -> f a

Compute the right scalar product

Example1 expression
V2 3 4 ^* 2V2 6 8
valuenegated :: (Functor f, Num a) => f a -> f a

Compute the negation of a vector

Example1 expression
negated (V2 2 4)V2 (-2) (-4)
valuescaled :: (Traversable t, Num a) => t a -> t (t a)

Produce a diagonal (scale) matrix from a vector.

Example1 expression
scaled (V2 2 3)V2 (V2 2 0) (V2 0 3)
classclass Additive (Diff p) => Affine (p :: Type -> Type) where

An affine space is roughly a vector space in which we have forgotten or at least pretend to have forgotten the origin.

a .+^ (b .-. a)  =  b@
(a .+^ u) .+^ v  =  a .+^ (u ^+^ v)@
(a .-. b) ^+^ v  =  (a .+^ v) .-. q@

Associated types

Methods

  • (.-.) :: Num a => p a -> p a -> Diff p ainfixl 6

    Get the difference between two points as a vector offset.

  • (.+^) :: Num a => p a -> Diff p a -> p ainfixl 6

    Add a vector offset to a point.

  • (.-^) :: Num a => p a -> Diff p a -> p ainfixl 6

    Subtract a vector offset from a point.

Instances20Affine, …
familytype family Diff (p :: Type -> Type) :: Type -> Type
#
Instances20Diff, …
  • type Diff Complex = ComplexDefined in linear-1.23.3 · Linear.Affine
  • type Diff IntMap = IntMapDefined in linear-1.23.3 · Linear.Affine
  • type Diff Identity = IdentityDefined in linear-1.23.3 · Linear.Affine
  • type Diff ZipList = ZipListDefined in linear-1.23.3 · Linear.Affine
  • type Diff Maybe = MaybeDefined in linear-1.23.3 · Linear.Affine
  • type Diff Plucker = PluckerDefined in linear-1.23.3 · Linear.Affine
  • type Diff Quaternion = QuaternionDefined in linear-1.23.3 · Linear.Affine
  • type Diff V0 = V0Defined in linear-1.23.3 · Linear.Affine
  • type Diff V1 = V1Defined in linear-1.23.3 · Linear.Affine
  • type Diff V2 = V2Defined in linear-1.23.3 · Linear.Affine
  • type Diff V3 = V3Defined in linear-1.23.3 · Linear.Affine
  • type Diff V4 = V4Defined in linear-1.23.3 · Linear.Affine
  • type Diff Vector = VectorDefined in linear-1.23.3 · Linear.Affine
  • type Diff (Product f g) = Product (Diff f) (Diff g)Defined in linear-1.23.3 · Linear.Affine
  • type Diff (Map k) = Map kDefined in linear-1.23.3 · Linear.Affine
  • type Diff (Point f) = fDefined in linear-1.23.3 · Linear.Affine
  • type Diff (V n) = V nDefined in linear-1.23.3 · Linear.Affine
  • type Diff (HashMap k) = HashMap kDefined in linear-1.23.3 · Linear.Affine
  • type Diff ((->) b) = (->) bDefined in linear-1.23.3 · Linear.Affine
  • type Diff [] = []Defined in linear-1.23.3 · Linear.Affine
newtypenewtype Point (f :: Type -> Type) a

A handy wrapper to help distinguish points from vectors at the type level

Constructors

  • P (f a)
Instances60Generic1, Monad, Functor, Applicative, Foldable, Traversable, …
classclass Num r => Algebra r m where

An associative unital algebra over a ring

Methods

  • mult :: (m -> m -> r) -> m -> r
  • unital :: r -> m -> r
Instances7Algebra, …
classclass Num r => Coalgebra r m where

A coassociative counital coalgebra over a ring

Methods

Instances10Coalgebra, …
classclass Num a => Conjugate a where

An involutive ring

Methods

  • conjugate :: a -> a

    Conjugate a value. This defaults to the trivial involution.

    Example1 expression
    conjugate (1 :+ 2)1.0 :+ (-2.0)
    Example1 expression
    conjugate 11
Instances17Conjugate, …
classclass Conjugate a => TrivialConjugate a

Requires and provides a default definition such that

conjugate = id
Instances15TrivialConjugate, …
newtypenewtype Covector r a

Linear functionals from elements of an (infinite) free module to a scalar

Constructors

Instances10Monad, Functor, Applicative, Alternative, MonadPlus, Alt, …
classclass Num a => Epsilon a where

Provides a fairly subjective test to see if a quantity is near zero.

Example1 expression
nearZero (1e-11 :: Double)False
Example1 expression
nearZero (1e-17 :: Double)True
Example1 expression
nearZero (1e-5 :: Float)False
Example1 expression
nearZero (1e-7 :: Float)True

Methods

Instances14Epsilon, …
typetype M22 a = V2 (V2 a)

A 2x2 matrix with row-major representation

typetype M23 a = V2 (V3 a)

A 2x3 matrix with row-major representation

typetype M24 a = V2 (V4 a)

A 2x4 matrix with row-major representation

typetype M32 a = V3 (V2 a)

A 3x2 matrix with row-major representation

typetype M33 a = V3 (V3 a)

A 3x3 matrix with row-major representation

typetype M34 a = V3 (V4 a)

A 3x4 matrix with row-major representation

typetype M42 a = V4 (V2 a)

A 4x2 matrix with row-major representation

typetype M43 a = V4 (V3 a)

A 4x3 matrix with row-major representation

typetype M44 a = V4 (V4 a)

A 4x4 matrix with row-major representation

classclass Additive f => Metric (f :: Type -> Type) where

Free and sparse inner product/metric spaces.

Methods

  • dot :: Num a => f a -> f a -> a

    Compute the inner product of two vectors or (equivalently) convert a vector f a into a covector f a -> a.

    Example1 expression
    V2 1 2 `dot` V2 3 411
  • quadrance :: Num a => f a -> a

    Compute the squared norm. The name quadrance arises from Norman J. Wildberger's rational trigonometry.

  • qd :: Num a => f a -> f a -> a

    Compute the quadrance of the difference

  • distance :: Floating a => f a -> f a -> a

    Compute the distance between two vectors in a metric space

  • norm :: Floating a => f a -> a

    Compute the norm of a vector in a metric space

  • signorm :: Floating a => f a -> f a

    Convert a non-zero vector to unit vector.

Instances19Metric, …
datadata Quaternion a

Quaternions

Constructors

Instances76Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
classclass Functor m => Trace (m :: Type -> Type) where
#

Methods

  • trace :: Num a => m (m a) -> a

    Compute the trace of a matrix

    Example1 expression
    trace (V2 (V2 a b) (V2 c d))a + d
  • diagonal :: m (m a) -> m a

    Compute the diagonal of a matrix

    Example1 expression
    diagonal (V2 (V2 a b) (V2 c d))V2 a d
Instances14Trace, …
datadata V0 a

A 0-dimensional vector

Example1 expression
pure 1 :: V0 IntV0
Example1 expression
V0 + V0V0
Instances67Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
  • Monad V0Defined in linear-1.23.3 · Linear.V0
  • Functor V0Defined in linear-1.23.3 · Linear.V0
  • MonadFix V0Defined in linear-1.23.3 · Linear.V0
  • Applicative V0Defined in linear-1.23.3 · Linear.V0
  • Foldable V0Defined in linear-1.23.3 · Linear.V0
  • Traversable V0Defined in linear-1.23.3 · Linear.V0
  • MonadZip V0Defined in linear-1.23.3 · Linear.V0
  • Eq1 V0Defined in linear-1.23.3 · Linear.V0
  • Ord1 V0Defined in linear-1.23.3 · Linear.V0
  • Read1 V0Defined in linear-1.23.3 · Linear.V0
  • Show1 V0Defined in linear-1.23.3 · Linear.V0
  • Hashable1 V0Defined in linear-1.23.3 · Linear.V0
  • Distributive V0Defined in linear-1.23.3 · Linear.V0
  • Apply V0Defined in linear-1.23.3 · Linear.V0
  • Bind V0Defined in linear-1.23.3 · Linear.V0
  • Representable V0Defined in linear-1.23.3 · Linear.V0
  • Serial1 V0Defined in linear-1.23.3 · Linear.V0
  • Metric V0Defined in linear-1.23.3 · Linear.V0
  • Trace V0Defined in linear-1.23.3 · Linear.Trace
  • Additive V0Defined in linear-1.23.3 · Linear.V0
  • Affine V0Defined in linear-1.23.3 · Linear.Affine
  • Finite V0Defined in linear-1.23.3 · Linear.V0
  • Generic1 V0Defined in linear-1.23.3 · Linear.V0
  • Lift (V0 a)Defined in linear-1.23.3 · Linear.V0
  • MVector MVector (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Vector Vector (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Num r => Algebra r (E V0)Defined in linear-1.23.3 · Linear.Algebra
  • Num r => Coalgebra r (E V0)Defined in linear-1.23.3 · Linear.Algebra
  • Bounded (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Enum (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Eq (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Floating (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Fractional (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Data a => Data (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Num (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Ord (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Read (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Show (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Ix (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Generic (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Semigroup (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Monoid (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Storable (V0 a)Defined in linear-1.23.3 · Linear.V0
  • NFData (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Random (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Uniform (V0 a)Defined in linear-1.23.3 · Linear.V0
  • UniformRange (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Binary (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Hashable (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Unbox (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Serialize (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Ixed (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Serial (V0 a)Defined in linear-1.23.3 · Linear.V0
  • Epsilon (V0 a)Defined in linear-1.23.3 · Linear.V0
  • FoldableWithIndex (E V0) V0Defined in linear-1.23.3 · Linear.V0
  • FunctorWithIndex (E V0) V0Defined in linear-1.23.3 · Linear.V0
  • TraversableWithIndex (E V0) V0Defined in linear-1.23.3 · Linear.V0
  • Each (V0 a) (V0 b) a bDefined in linear-1.23.3 · Linear.V0
  • type Rep (V0 a) = D1 ('MetaData "V0" "Linear.V0" "linear-1.23.3-Dl2ajNWhf8D1bTiVYHPY8v" 'False) (C1 ('MetaCons "V0" 'PrefixI 'False) U1)Defined in linear-1.23.3 · Linear.V0
  • type Rep1 V0 = D1 ('MetaData "V0" "Linear.V0" "linear-1.23.3-Dl2ajNWhf8D1bTiVYHPY8v" 'False) (C1 ('MetaCons "V0" 'PrefixI 'False) U1)Defined in linear-1.23.3 · Linear.V0
  • data MVector s (V0 a)Defined in linear-1.23.3 · Linear.V0
  • data Vector (V0 a)Defined in linear-1.23.3 · Linear.V0
  • type Rep V0 = E V0Defined in linear-1.23.3 · Linear.V0
  • type Index (V0 a) = E V0Defined in linear-1.23.3 · Linear.V0
  • type IxValue (V0 a) = aDefined in linear-1.23.3 · Linear.V0
  • type Diff V0 = V0Defined in linear-1.23.3 · Linear.Affine
  • type Size V0 = 0Defined in linear-1.23.3 · Linear.V0
classclass R1 (t :: Type -> Type) where

A space that has at least 1 basis vector _x.

Methods

  • _x :: Lens' (t a) a
    Example1 expression
    V1 2 ^._x2
    Example1 expression
    V1 2 & _x .~ 3V1 3
Instances7R1, …
  • R1 IdentityDefined in linear-1.23.3 · Linear.V1
  • R1 QuaternionDefined in linear-1.23.3 · Linear.Quaternion
  • R1 V1Defined in linear-1.23.3 · Linear.V1
  • R1 V2Defined in linear-1.23.3 · Linear.V2
  • R1 V3Defined in linear-1.23.3 · Linear.V3
  • R1 V4Defined in linear-1.23.3 · Linear.V4
  • R1 f => R1 (Point f)Defined in linear-1.23.3 · Linear.Affine
newtypenewtype V1 a

A 1-dimensional vector

Example1 expression
pure 1 :: V1 IntV1 1
Example1 expression
V1 2 + V1 3V1 5
Example1 expression
V1 2 * V1 3V1 6
Example1 expression
sum (V1 2)2

Constructors

Instances70Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
classclass R1 t => R2 (t :: Type -> Type) where

A space that distinguishes 2 orthogonal basis vectors _x and _y, but may have more.

Methods

  • _y :: Lens' (t a) a
    Example1 expression
    V2 1 2 ^._y2
    Example1 expression
    V2 1 2 & _y .~ 3V2 1 3
  • _xy :: Lens' (t a) (V2 a)
Instances5R2
  • R2 QuaternionDefined in linear-1.23.3 · Linear.Quaternion
  • R2 V2Defined in linear-1.23.3 · Linear.V2
  • R2 V3Defined in linear-1.23.3 · Linear.V3
  • R2 V4Defined in linear-1.23.3 · Linear.V4
  • R2 f => R2 (Point f)Defined in linear-1.23.3 · Linear.Affine
datadata V2 a

A 2-dimensional vector

Example1 expression
pure 1 :: V2 IntV2 1 1
Example1 expression
V2 1 2 + V2 3 4V2 4 6
Example1 expression
V2 1 2 * V2 3 4V2 3 8
Example1 expression
sum (V2 1 2)3

Constructors

Instances71Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
classclass R2 t => R3 (t :: Type -> Type) where

A space that distinguishes 3 orthogonal basis vectors: _x, _y, and _z. (It may have more)

Methods

Instances4R3
  • R3 QuaternionDefined in linear-1.23.3 · Linear.Quaternion
  • R3 V3Defined in linear-1.23.3 · Linear.V3
  • R3 V4Defined in linear-1.23.3 · Linear.V4
  • R3 f => R3 (Point f)Defined in linear-1.23.3 · Linear.Affine
datadata V3 a

A 3-dimensional vector

Constructors

  • V3 !a !a !a
Instances73Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
classclass R3 t => R4 (t :: Type -> Type) where

A space that distinguishes orthogonal basis vectors _x, _y, _z, _w. (It may have more.)

Methods

Instances3R4
  • R4 QuaternionDefined in linear-1.23.3 · Linear.Quaternion
  • R4 V4Defined in linear-1.23.3 · Linear.V4
  • R4 f => R4 (Point f)Defined in linear-1.23.3 · Linear.Affine
datadata V4 a

A 4-dimensional vector.

Constructors

  • V4 !a !a !a !a
Instances75Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
classclass Functor f => Additive (f :: Type -> Type) where

A vector is an additive group with additional structure.

Methods

  • zero :: Num a => f a

    The zero vector

  • (^+^) :: Num a => f a -> f a -> f ainfixl 6

    Compute the sum of two vectors

    Example1 expression
    V2 1 2 ^+^ V2 3 4V2 4 6
  • (^-^) :: Num a => f a -> f a -> f ainfixl 6

    Compute the difference between two vectors

    Example1 expression
    V2 4 5 ^-^ V2 3 1V2 1 4
  • lerp :: Num a => a -> f a -> f a -> f a

    Linearly interpolate between two vectors.

    Since linear version 1.23, interpolation direction has been reversed; now

    lerp 0 a b == a
    lerp 1 a b == b
  • liftU2 :: (a -> a -> a) -> f a -> f a -> f a

    Apply a function to merge the 'non-zero' components of two vectors, unioning the rest of the values.

    • For a dense vector this is equivalent to liftA2.

    • For a sparse vector this is equivalent to unionWith.

  • liftI2 :: (a -> b -> c) -> f a -> f b -> f c

    Apply a function to the components of two vectors.

Instances21Additive, …
newtypenewtype E (t :: Type -> Type)

Basis element

Constructors

Instances32Algebra, Coalgebra, FoldableWithIndex, FunctorWithIndex, TraversableWithIndex, …
data familydata family MVector s a
#
Instances114NFData1, NFData, MVector, …
data familydata family Vector a
#
Instances135NFData1, IsList, Eq, Data, Ord, Read, …

Point

newtypenewtype Point (f :: Type -> Type) a

A handy wrapper to help distinguish points from vectors at the type level

Constructors

  • P (f a)
Instances60Generic1, Monad, Functor, Applicative, Foldable, Traversable, …

Vectors

datadata V2 a

A 2-dimensional vector

Example1 expression
pure 1 :: V2 IntV2 1 1
Example1 expression
V2 1 2 + V2 3 4V2 4 6
Example1 expression
V2 1 2 * V2 3 4V2 3 8
Example1 expression
sum (V2 1 2)3

Constructors

Instances71Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
datadata V3 a

A 3-dimensional vector

Constructors

  • V3 !a !a !a
Instances73Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
datadata V4 a

A 4-dimensional vector.

Constructors

  • V4 !a !a !a !a
Instances75Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …