Skip to content
compile-time checked units for linear algebra
Haskell Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Compile-time checked units for matrices

Two related generalizations of dimensional are explored in this package:

  • wrap hmatrix operations to check physical units and dimensions at compile time.
  • automatic differentiation (ad package) that knows about units

This comes at a cost, since type errors become more complicated, and type signatures for functions that operate on the involved quantities are more difficult (see examples/controlspace.hs). In return, you get a stronger assurance that the program does the right thing.

Additionally, there is an emphasis on type inference going both ways: in ordinary haskell this is pretty much provided. For example if we have, z = x + y, then if due to other parts of the program the compiler knows x :: (Int,_1,_2), y :: (_3,Int,_4) and z :: (_5,_6,Int), it can conclude that (+) is needed with type (Int,Int,Int) -> (Int,Int,Int) -> (Int,Int,Int) [^note]. This means using things with kind Constraint (class/type/type family) instead of type families.

[^note]: which isn't available by default, but you can check or write it by hand

Haddocks are available at


Get ghc-7.6 or ghc-7.8 and cabal-install. Then:

cabal install cabal-meta cabal-src
git clone
cd DimMat/
cabal-meta install

Related Work

Units and AD or linear algebra

Matrix dimensions statically checked

These packages provide operations where the typechecker will prevent invalid operations, such as multiplying an m×n matrix with a p×q matrix when n /= p, at compile-time.



extensible records have many needs in common with DimMat. Types in HMatrix like fromBlocks :: [[Matrix t]] -> Matrix t are (or will be) generalized to use HList instead of ordinary lists ([]).

You can’t perform that action at this time.