BSD-3-Clause licensed by Edward A. Kmett
Maintained by Edward A. Kmett
This version can be pinned in stack with:linear-1.22@sha256:1eb1524496f3baf6f66d3d1e8faa037c77c26a33026b073e6d3c733df3f0514f,4132


Hackage Build Status

Highly polymorphic vector space operations on sparse and free vector spaces.

Contact Information

Contributions and bug reports are welcome!

Please feel free to contact me through github or on the #haskell IRC channel on

-Edward Kmett


1.22 [2022.11.30]

  • The types of _Point and lensP have been generalized:

    -_Point :: Iso' (Point f a) (f a)
    +_Point :: Iso (Point f a) (Point g b) (f a) (g b)
    -lensP :: Lens' (Point g a) (g a)
    +lensP :: Lens (Point f a) (Point g b) (f a) (g b)

    There is a chance that existing uses of _Point or lensP will fail to typecheck due to their more general types. You can use _Point.simple or lensP.simple to restore their old, more restricted types (where simple comes from Control.Lens in the lens library).

1.21.10 [2022.06.21]

  • Allow building with vector-0.13.*.

1.21.9 [2022.05.18]

  • Allow building with transformers-0.6.*.

1.21.8 [2021.11.15]

  • Allow building with hashable-1.4.*.
  • Drop support for pre-8.0 versions of GHC.

1.21.7 [2021.09.20]

  • Fix a build error when using random-1.2.1 or later.

1.21.6 [2021.07.05]

  • Fix a build error when configured with -template-haskell.

1.21.5 [2021.02.18]

  • Allow building with lens-5.*.

1.21.4 [2021.01.29]

  • Allow building with vector-0.12.2 or later.
  • The build-type has been changed from Custom to Simple. To achieve this, the doctests test suite has been removed in favor of using cabal-docspec to run the doctests.

1.21.3 [2020.10.03]

  • Allow building with GHC 9.0.

1.21.2 [2020.09.30]

  • Use base-orphans-0.8.3 or later. This means that the Linear.Instances module no longer defines any orphan instances of its own, and the module is now a simple shim on top of Data.Orphans from base-orphans.

1.21.1 [2020.06.25]

  • Allow building with random-1.2.*.

1.21 [2020.02.03]

  • Add instances for direct sums (Product) and tensor products (Compose) of other vector spaces. This makes is much more convenient to do things like treat a matrix temporarily as a vector through Compose, or to consider things like Gauss-Jordan elimination, which wants augmented structures.
  • Add frobenius for computing the Frobenius norm of a matrix.
  • Added Random instances for System.Random. We had an indirect dependency through vector anyways.
  • Add “obvious” zipping Semigroup and Monoid instances to all the representable vector spaces.
  • Add R1..R4 instances to Quaternion. _w is the scalar component so that _x,_y,_z can be directional.
  • Add more solvers to Linear.Matrix, available with base-4.8 or later.
  • Add unangle function to Linear.V2.

1.20.9 [2019.05.02]

  • Derive Lift instances for Plucker, Quaternion, and V{0,1,2,3,4}.

1.20.8 [2018.07.03]

  • Add instances of the Field classes from lens.
  • Add Epsilon instance for Complex.
  • Use specialized implementations of the null and length methods in Foldable instances.
  • Add Hashable1 instances for data types in linear. Also add a Hashable instance for V.
  • Fix a bug in which Quaternions were incorrectly exponentiated.


  • Support semigroupoids-5.2.1 and doctest-0.12


  • Revamp Setup.hs to use cabal-doctest. This makes it build with Cabal-2.0, and makes the doctests work with cabal new-build and sandboxes.
  • Make (1 / x) and recip x agree in the Fractional instance for Quaternion
  • Use newtype instances for Point vectors in Linear.Affine
  • Enable PolyKinds in Linear.Trace. Also enable PolyKinds when GHC 7.6 or later is used (previously, it was GHC 7.8 or later).
  • Fix a segfault arising from the MVector instance for V
  • Add Finite class for conversion between V and fixed-size vector types


  • GHC 8 compatibility
  • Fixed the perspective calculation.


  • Compatibility with base-orphans 0.5


  • Support vector
  • Support cereal 0.5
  • You can now unboxed vectors of V n vectors.


  • Modified the doctest machinery to work with stack and builds to non-standard locations.
  • Removed the local .ghci file.
  • Various numerical stability improvements were made to the quaternion and projection functions.


  • Fixed doctests broken by the previous change.
  • Unboxed vector instances for various linear data types now use unpacked integers even on older GHCs.


  • inv22, inv33 and inv44 no longer attempt an epsilon check. They no longer return a Maybe result as a consequence. You should filter for the 0 determinant case yourself.

  • vector support

  • Fix GHC 7.4.

  • Proper reflection 2 support


  • reflection 2 support


  • Change the Ixed instance for Linear.V to use Int as the index type. This makes V n a lot easier to use.


  • Compile warning-free on GHC 7.10.


  • Added NFData instance for Point


  • Added an -f-template-haskell option to allow disabling template-haskell support. This is an unsupported configuration but may be useful for expert users in sandbox configurations.
  • Added lenses for extracting corner various sub-matrices e.g. _m22, _m33

  • Fixed builds on even older GHCs.

  • Fixed the test suite.
  • Fixed builds on older GHCs.


  • Consolidated eye2 .. eye4 into a single identity combinator.
  • Fixed the Data instance V n a for GHC 7.10-RC3.

  • filepath 1.4 support


  • Added support for Data.Functor.Classes from transformers 0.5 via transformers-compat.
  • Added missing support for binary, bytes and cereal for Point


  • Better support for binary. Added support for bytes and cereal


  • ortho and inverseOrtho now only require a Fractional constraint.
  • Added missing Floating instances.


  • Improve the performance of fromQuaternion, mkTransformation, mkTransformationMat, basisFor, scaled by using implementations that inline well for functions that were previously reference implementations.


  • Added NFData instances for the various vector types.
  • Added !!/ operator for matrix division by scalar.


  • Added Trace instance for V1.


  • Renamed kronecker to scaled.


  • Added Metric instances for [], ZipList, Maybe
  • Added det44 and inv44 to Linear.Matrix
  • Added Data instance for Point


  • Added Typeable and Data instances for V


  • Added missing FunctorWithIndex, FoldableWithIndex and TraversableWithIndex Int (V n) instances for V


  • Added frustum, analogous to the old glFrustum call.
  • Added inverseInfinitePerspective, inverseOrtho, inverseFrustum.


  • Added inversePerspective. It is much more accurate to compute it directly than to compute an inverse.

  • Fixed build failures caused by Linear re-exporting the old name.


  • Renamed Linear.Perspective to Linear.Projection.
  • Fixed a build issue with GHC HEAD.

  • Fixed test failures caused by 1.14


  • Moved Coincides to Linear.Plucker.Coincides. The constructors Line and Ray oft collided with user code.


  • Switched ‘ortho’ to follow the OpenGL handedness.


  • Added “swizzle” lenses e.g. _yzx, which are useful for working with libraries like gl.


  • Added ‘transpose’
  • Added missing ‘Mxy’ matrices up to 4 dimensions – they were commonly reimplemented by users.


  • Fixed an issue with UndecidableInstances on GHC 7.6.3


  • Added Linear.Perspective.


  • Added _Point, relative and a few instances for Point.


  • Changed the ‘representation’ of V n from E (V n), which was hard to use, to Int, which is a bit too permissive, but is easy to use.


  • Added Linear.V2.angle.


  • Added Hashable instances.


  • Added a role annotation to V n a to prevent users from using GHC 7.8’s Coercible machinery to violate invariants.

  • Fixed a broken build


  • Added MonadZip instances.
  • Added MonadFix instances.
  • Added Control.Lens.Each.Each instances


  • Bugfixed slerp


  • Added missing Unbox instances for working with unboxed vectors of linear data types.


  • Fixed axisAngle
  • unit now has a rank 1 type.


  • lens 4 compatibility


  • Renamed incore to column and added an example.

  • Build bugfix


  • Better implementations of basis and basisFor.
  • Derived Generic instances.


  • Improved matrix multiplication to properly support the sparse/sparse case.


  • Marked modules Trustworthy as necessary.


  • Dependency bump for reflection compatibility


  • Fixed an infinite loop in the default definition of liftI2.


  • Added Additive instances for [], Maybe and Vector.


  • Strict vectors
  • Exported mkTransformationMat
  • Bumped dependency bounds

0.9.1 [bug fix]

  • Exported Linear.V0!


  • Added sparse vector support.


  • Added Linear.V0


  • Added Linear.Instances
  • More documentation


  • Removed the direct dependency on lens.
  • Added Linear.Core to cover vector spaces as corepresentable functors.


  • Added Ix instances for V2, V3, and V4

  • Removed the upper bound on distributive


  • Initial hackage release