#type-level #natural #numbers

nightly type-nats

Type-level natural numbers in Rust

2 releases

Uses old Rust 2015

0.0.2 Jan 1, 2015
0.0.1 Dec 29, 2014

#2860 in Rust patterns

MIT license

11KB
306 lines

type-nats.rs

Type-level natural numbers in Rust

build status

Synopsis

This library implements type-level natural numbers using traits and associated types. At this stage it is meant to serve as a demonstration more than anything else.

Examples

    fn example() {
        let _: SNat< S<S<S<S<S<Z>>>>> > = Add::< S<S<S<Z>>> , S<S<Z>> >::query();
        let _: SNat< N06 > = Mul::< N03 , N02 >::query();
        let _: SNat< N08 > = Exp::< N03 , N02 >::query();
        let _: SNat< N24 > = Fac::< N04       >::query();

        assert_eq!(Add::< N03 , N02 >::to_uint(), 5u);
        assert_eq!(Mul::< N03 , N02 >::to_uint(), 6u);
        assert_eq!(Exp::< N03 , N02 >::to_uint(), 8u);
        assert_eq!(Fac::< N04       >::to_uint(), 24u);
    }

Documentation

See the API documentation here.

Requirements

  1. Rust
  2. Cargo

You can install both with the following:

$ curl -s https://static.rust-lang.org/rustup.sh | sudo sh

See Installing Rust for further details.

Usage

$ cargo build       ## build library and binary
$ cargo test        ## run tests in ./tests
$ cargo bench       ## run benchmarks in ./benches

Discussion

There is an IRC channel on freenode (chat.freenode.net) at #epsilonz.

No runtime deps