Skip to content

Instantly share code, notes, and snippets.

@Sgeo
Created August 17, 2016 22:43
Show Gist options
  • Save Sgeo/e1a604eb4aeff926cd03fe5553e1b835 to your computer and use it in GitHub Desktop.
Save Sgeo/e1a604eb4aeff926cd03fe5553e1b835 to your computer and use it in GitHub Desktop.
With help of talchas
#![feature(type_macros)]
struct Zero;
struct Succ<T>(T);
macro_rules! newtype {
($name_:ident) => {
get_and_inc!($name_, Zero);
}
}
macro_rules! get_and_inc {
($name:ident, $ty:ty) => {
macro_rules! newtype {
($name_:ident) => {
get_and_inc!($name_, Succ<$ty>);
}
}
type $name = $ty;
}
}
newtype!(A);
newtype!(B);
fn main() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment