HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulelinear-1.22Haskell2010

Linear.Vector

Operations on free vector spaces.

  • 1 type
  • 1 class
  • 10 values
  • Packagelinear-1.22
  • Exports12
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceVector.hs
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.

  • 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, …
valuenegated :: (Functor f, Num a) => f a -> f a
#

Compute the negation of a vector

Example1 expression
negated (V2 2 4)V2 (-2) (-4)
value(^*) :: (Functor f, Num a) => f a -> a -> f a
#

Compute the right scalar product

Example1 expression
V2 3 4 ^* 2V2 6 8
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, Fractional a) => f a -> a -> f a
#

Compute division by a scalar on the right.

valuesumV :: (Foldable f, Additive v, Num a) => f (v a) -> v a
#

Sum over multiple vectors

Example1 expression
sumV [V2 1 1, V2 3 4]V2 4 5
valuebasis :: (Additive t, Traversable t, Num a) => [t a]
#

Produce a default basis for a vector space. If the dimensionality of the vector space is not statically known, see basisFor.

valuebasisFor :: (Traversable t, Num a) => t b -> [t a]
#

Produce a default basis for a vector space from which the argument is drawn.

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)
valueunit :: (Additive t, Num a) => ASetter' (t a) a -> t a
#

Create a unit vector.

Example1 expression
unit _x :: V2 IntV2 1 0