Skip to content

Instantly share code, notes, and snippets.

@erickt
Created July 17, 2012 21:28
Show Gist options
  • Select an option

  • Save erickt/3132223 to your computer and use it in GitHub Desktop.

Select an option

Save erickt/3132223 to your computer and use it in GitHub Desktop.
pure unique lists
enum list<T> {
cons(T, ~list<T>),
nil,
}
fn iter<T>(xs: list<T>, f: fn(T)) {
alt xs {
cons(x, xs) {
f(x);
iter::<T>(*xs, f)
}
nil { }
}
}
fn main() {
let xs = cons(~"a", ~cons(~"b", ~cons(~"c", ~nil)));
iter(xs, |x| #error("%?", x));
iter(xs, |x| #error("%?", x));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment