Macro polytype::tp [] [src]

macro_rules! tp {
    ($n:ident) => { ... };
    ($n:ident($($x:expr),*)) => { ... };
    ($n:ident($($x:expr,)*)) => { ... };
    ($n:expr) => { ... };
}

Creates a Type::Constructed or Type::Variable (convenience for common pattern).

This example is not tested
// equivalent to:
Type::Constructed(ident, vec![
    tp1,
    tp2,
    ...
])
// or
Type::Variable(n)

Examples

Make a primitive type:

let t = tp!(int);
assert_eq!(format!("{}", t), "int");
// equivalent to:
let t_eq = Type::Constructed("int", vec![]);
assert_eq!(t, t_eq);

Make a variable type:

let t = tp!(0);
assert_eq!(format!("{}", t), "t0");
// equivalent to:
let t_eq = Type::Variable(0);
assert_eq!(t, t_eq);

Make a composite type:

let tint = tp!(int);
let tstr = tp!(str);
let t = tp!(dict(tstr, tint));
assert_eq!(format!("{}", t), "dict(str,int)");
// equivalent to:
let t_eq = Type::Constructed("dict", vec![
    Type::Constructed("str", vec![]),
    Type::Constructed("int", vec![]),
]);
assert_eq!(t, t_eq);

Nest them for more complex types:

// mapi: (int → α → β) → [α] → [β]
let t = arrow![
    arrow![tp!(int), tp!(0), tp!(1)],
    tp!(list(tp!(0))),
    tp!(list(tp!(1))),
];
assert_eq!(format!("{}", t), "(int → t0 → t1) → list(t0) → list(t1)");