peano: Peano numbers

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]


Lazy unary natural numbers.

[Skip to Readme]


Change log
Dependencies base (>=4.9 && <5) [details]
License BSD-3-Clause
Author M Farkas-Dyck, Andreas Abel
Maintainer Andreas Abel
Category Data, Math
Source repo head: git clone
Uploaded by AndreasAbel at 2023-10-23T09:21:52Z


[Index] [Quick Jump]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Readme for peano-

[back to package description]

peano - Lazy unary natural numbers

This package provides natural numbers in unary notation

data Peano
  = Zero
  | Succ Peano

implementing Num, Ord etc.


One application is to check whether the length of a (potentially long) list is greater than a (small) number.

E.g., without optimization (-O 0),

genericLength (replicate (10 ^ 6) True) >= (5 :: Peano)

outperforms the same test for 5 :: Int by a factor of 10⁵, see benchmark:

    Peano: OK
      450  ns ±  45 ns
    Int:   OK
      136  ms ± 4.1 ms