Skip to content

Instantly share code, notes, and snippets.

@hatahet
Forked from erickt/gist:3132223
Created July 31, 2012 07:23
Show Gist options
  • Select an option

  • Save hatahet/3214490 to your computer and use it in GitHub Desktop.

Select an option

Save hatahet/3214490 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