Two related generalizations of dimensional are explored in this package:
- wrap hmatrix operations to check physical units and dimensions at compile time.
- automatic differentiation (
adpackage) 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) 1.
This means using things with kind Constraint (class/type/type family) instead
of type families.
Haddocks are available at http://aavogt.github.io/haddock/DimMat
Get ghc-7.6 or ghc-7.8 and cabal-install. Then:
cabal install cabal-meta cabal-src
git clone https://github.com/aavogt/DimMat
cd DimMat/
cabal-meta install- dimensional-vectors is smaller, and uses a
[[a]]representation of the data instead ofData.Packed.Matrix a - https://github.com/dmcclean/dimensional-dk-linalg shares some code with DimMat, but
- https://github.com/bjornbm/dimensional-experimental/blob/master/Numeric/Units/Dimensional/AD.hs has the same wrapper for AD
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.
- http://hackage.haskell.org/package/vector-static
- http://hackage.haskell.org/package/linear
- http://hackage.haskell.org/package/Vec
- http://hackage.haskell.org/package/hmatrix-static
- vectro is a relatively early library
- vector-space has limited operations on tuples (up to 4 elements)
- tensor has the number of indices at type level, but the range over which index varies is checked at runtime some of the time
- storable-static-array uses ghc-7.8 features
- The haskellwiki physical units mentions several methods to check units at compile time or at run-time
- https://github.com/haasn/units
- https://github.com/adamgundry/inch/ is a preprocessor for type-level integers with an examples involving units
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 ([]).
Footnotes
-
which isn't available by default, but you can check http://hackage.haskell.org/package/NumInstances or write it by hand ↩