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]

Warnings:

Lazy unary natural numbers.


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.2
Change log CHANGELOG.md
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 https://github.com/andreasabel/peano.hs
Uploaded by AndreasAbel at 2023-10-23T09:21:52Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for peano-0.1.0.2

[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.

Purpose

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:

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