Skip to content

Instantly share code, notes, and snippets.

@msullivan
Created July 2, 2012 19:01
Show Gist options
  • Save msullivan/3034982 to your computer and use it in GitHub Desktop.
Save msullivan/3034982 to your computer and use it in GitHub Desktop.
iface builder<A> {
// This would have some methods
}
impl extensions<A: copy> of builder<A> for @[A] { }
// Pretend that these are static typeclass methods
fn new_container<A,IA:builder<A>>() -> IA {
fail "this is a dummy for type inference testing!"
}
fn push<A,IA:builder<A>>(&_v: IA, +_x: A) {
fail "this is a dummy for type inference testing!"
}
fn build_from_vec<A:copy,IA:builder<A>>(v: &[A]) -> IA {
let mut new_v = new_container();
for v.each() |x| {
push(new_v, x);
}
ret new_v;
}
fn main() {
let x: @[int] = build_from_vec([1,2,3]/_);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment