https://github.com/andreasabel/peano.hs
Peano numbers
https://github.com/andreasabel/peano.hs
Last synced: about 1 year ago
JSON representation
Peano numbers
- Host: GitHub
- URL: https://github.com/andreasabel/peano.hs
- Owner: andreasabel
- License: other
- Created: 2022-11-26T21:04:30.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-10-23T09:30:20.000Z (over 2 years ago)
- Last Synced: 2025-05-05T20:05:00.057Z (about 1 year ago)
- Language: Haskell
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
peano - Lazy unary natural numbers
==================================
This package provides natural numbers in unary notation
```haskell
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`),
```haskell
genericLength (replicate (10 ^ 6) True) >= (5 :: Peano)
```
outperforms the same test for `5 :: Int` by a factor of 10⁵, see [benchmark](bench/Main.hs):
```
length
Peano: OK
450 ns ± 45 ns
Int: OK
136 ms ± 4.1 ms
```