Created
October 31, 2016 02:46
-
-
Save sdleffler/ece9b3448cde24de358778d49dea8902 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::marker::PhantomData; | |
mod arith; | |
pub use self::arith::*; | |
pub trait Nat { | |
fn as_usize() -> usize; | |
} | |
pub struct Z; | |
pub struct S<N: Nat>(PhantomData<N>); | |
impl Nat for Z { | |
fn as_usize() -> usize { | |
0 | |
} | |
} | |
impl<N: Nat> Nat for S<N> { | |
fn as_usize() -> usize { | |
1 + N::as_usize() | |
} | |
} | |
#[macro_export] | |
macro_rules! peano_count { | |
($elem:expr $(, $rest:expr)*) => ($crate::peano::S<peano_count!($($rest),*)>); | |
() => ($crate::peano::Z); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment