A haskell numeric prelude, providing a clean structure for numbers and operations that combine them.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.



Build Status Gitter chat

A numeric class heirarchy, providing a structure for numbers and functions that combine them.

Ring heirarchy

For example, the Num class in prelude is approximately a Ring. In numhask, the class laws and operators flow as follows:

Ring Hierarchy


  • numhask the core class heirarchy with just base as a dependency
  • numhask-prelude numhask + protolude
  • numhask-array n-dimensional arrays with type-level size

There is also some performance analytics in numhask-bench and numhask-graph produces the above chart.


Hackage lts nightly

numhask begins with separately named magma-derived classes for addition and multiplication, and then being symetrical in the treatment of the two heirarchies. A short magma structure is provided with the intention of supplying appropriate classes for operators that are neither addition nor multiplication, but this structure is not hooked up to the main classes.

To be as compatible as practical with the existing haskell ecosystem. Ints, Integers, Floats, Doubles and Complex are taken from base and given numhask class instances, so they are also Num instances. Monoid and Semigroup are not used in numhask to maintain compatability.

numhask replaces all the relevant numeric operators in Prelude, so you're going to get clashes.

QuickCheck tests of numeric laws are included. This also includes tracking where laws are approximate or fail for non-exact numbers.

The usual operators (+) and (*) operators are reserved for commutative relationships, with plus and times being used for non-commutative ones.

In summary, the library doesn't do anything fancy. But if having to define (*) when you just want a (+) offends your sensibilities, it may bring some sanity.


Hackage lts nightly

{-# LANGUAGE NoImplicitPrelude #-}
import NumHask.Prelude

'Numhask.Prelude' is designed as a drop-in replacement for Prelude and 'NoImplicitPrelude' is obligatory. Behind the scenes, the module wraps protolude.

See Examples for basic examples, or numhask-range for slightly heavier usage.


Hackage lts nightly

Testing framework for numhask, based around hedgehog.


Hackage lts nightly

An experimental array with:

  • a polymorphic container
  • shape specified at the type level
  • Representable instances

See Examples for the emergent API.

To try out in ghci:

stack ghci
> :set -XDataKinds
> :set -XOverloadedLists
> import NumHask.Prelude
> import NumHask.Array
> let a = [0..5] :: Array [] '[2,3] Int
> a + a
[[0, 2, 4],
 [6, 8, 10]]


See bench for current performance results.

cd numhask-bench
stack build --exec "$(stack path --local-install-root)/bin/numhask-bench" --exec "$(stack path --local-bin)/pandoc -f markdown -i other/bench_.md -t markdown -o readme.md --filter pandoc-include --mathjax" --file-watch