HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Modulelinear-1.23.3Haskell2010

Linear.Vector

Operations on free vector spaces.

Synopsis
  • Packagelinear-1.23.3
  • 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.

    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, …
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
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)