use std;
import std::vec;
-fn ivec_equal[T](v: &[T], u: &[T], element_equality_test: fn(&T, &T) -> bool )
+fn ivec_equal<T>(v: &[T], u: &[T], element_equality_test: fn(&T, &T) -> bool )
-> bool {
let Lv = vec::len(v);
if Lv != vec::len(u) { ret false; }
ret true;
}
-fn builtin_equal[T](a: &T, b: &T) -> bool { ret a == b; }
+fn builtin_equal<T>(a: &T, b: &T) -> bool { ret a == b; }
fn main() {
assert (builtin_equal(5, 5));
two functions, "return the number of possible edits" and "return edit #n"
It would be nice if this could be data-driven, so the two functions could share information:
- type vec_modifier = rec(fn (&[T] v, uint i) -> [T] fun, uint lo, uint di);
+ type vec_modifier = rec(fn (&<T> v, uint i) -> [T] fun, uint lo, uint di);
const [vec_modifier] vec_modifiers = ~[rec(fun=vec_omit, 0u, 1u), ...];
But that gives me "error: internal compiler error unimplemented consts that's not a plain literal".
https://github.com/graydon/rust/issues/570
import std::ivec::len;
import std::int;
-//fn vec_reverse(&[T] v) -> [T] { ... }
+//fn vec_reverse(&<T> v) -> [T] { ... }
-fn vec_omit[T](v: &[T], i: uint) -> [T] {
+fn vec_omit<T>(v: &[T], i: uint) -> [T] {
slice(v, 0u, i) + slice(v, i + 1u, len(v))
}
-fn vec_dup[T](v: &[T], i: uint) -> [T] {
+fn vec_dup<T>(v: &[T], i: uint) -> [T] {
slice(v, 0u, i) + ~[v.(i)] + slice(v, i, len(v))
}
-fn vec_swadj[T](v: &[T], i: uint) -> [T] {
+fn vec_swadj<T>(v: &[T], i: uint) -> [T] {
slice(v, 0u, i) + ~[v.(i + 1u), v.(i)] + slice(v, i + 2u, len(v))
}
-fn vec_prefix[T](v: &[T], i: uint) -> [T] { slice(v, 0u, i) }
-fn vec_suffix[T](v: &[T], i: uint) -> [T] { slice(v, i, len(v)) }
+fn vec_prefix<T>(v: &[T], i: uint) -> [T] { slice(v, 0u, i) }
+fn vec_suffix<T>(v: &[T], i: uint) -> [T] { slice(v, i, len(v)) }
-fn vec_poke[T](v: &[T], i: uint, x: &T) -> [T] {
+fn vec_poke<T>(v: &[T], i: uint, x: &T) -> [T] {
slice(v, 0u, i) + ~[x] + slice(v, i + 1u, len(v))
}
-fn vec_insert[T](v: &[T], i: uint, x: &T) -> [T] {
+fn vec_insert<T>(v: &[T], i: uint, x: &T) -> [T] {
slice(v, 0u, i) + ~[x] + slice(v, i, len(v))
}
}
// Returns a bunch of modified versions of v, some of which introduce new elements (borrowed from xs).
-fn vec_edits[T](v: &[T], xs: &[T]) -> [[T]] {
+fn vec_edits<T>(v: &[T], xs: &[T]) -> [[T]] {
let edits: [[T]] = ~[];
let Lv: uint = len(v);
// xfail-stage2
// xfail-stage3
// error-pattern: attempted dynamic environment-capture
-fn foo[T]() {
+fn foo<T>() {
obj bar(b: T) { }
}
-fn main() { }
\ No newline at end of file
+fn main() { }
// error-pattern: Dynamically sized arguments must be passed by alias
mod foo {
- fn bar[T](f: T) -> int { ret 17; }
- type bar[U, T] = {a: int, b: U, c: T};
+ fn bar<T>(f: T) -> int { ret 17; }
+ type bar<U, T> = {a: int, b: U, c: T};
}
-fn main() { }
\ No newline at end of file
+fn main() { }
// error-pattern:Attempt to use a type argument out of scope
-fn hd[U](v: &[U]) -> U {
+fn hd<U>(v: &[U]) -> U {
fn hd1(w: &[U]) -> U { ret w.(0); }
ret hd1(v);
// error-pattern:mismatched types
// From Issue #778
-tag clam[T] { a(T); }
+tag clam<T> { a(T); }
fn main() { let c; c = a(c); alt c { a[int](_) { } } }
// error-pattern: Wrong number of type arguments
-tag quux[T] { }
+tag quux<T> { }
fn foo(c: quux) { assert (false); }
-fn main() { fail; }
\ No newline at end of file
+fn main() { fail; }
// error-pattern:Attempt to use a type argument out of scope
-fn foo[T](x: &T) {
+fn foo<T>(x: &T) {
fn bar(f: fn(&T) -> T ) { }
}
-fn main() { foo(1); }
\ No newline at end of file
+fn main() { foo(1); }
}
}
-fn with_lib_path[T](path: &str, f: fn() -> T ) -> T {
+fn with_lib_path<T>(path: &str, f: fn() -> T ) -> T {
let maybe_oldpath = getenv(util::lib_path_env_var());
append_lib_path(path);
let res = f();
type task_id = int;
type port_id = int;
-type chan_t[~T] = {
+type chan_t<~T> = {
task : task_id,
port : port_id
};
-fn send[~T](ch : chan_t<T>, data : -T) { fail; }
+fn send<~T>(ch : chan_t<T>, data : -T) { fail; }
fn main() { fail "quux"; }
import std::comm::mk_port;
import std::comm::send;
-fn echo[~T](c: _chan<T>, oc: _chan<_chan<T>>) {
+fn echo<~T>(c: _chan<T>, oc: _chan<_chan<T>>) {
// Tests that the type argument in port gets
// visited
let p = mk_port[T]();
-tag option[T] { some(T); none; }
+tag option<T> { some(T); none; }
-type r[T] = {mutable v: [option<T>]};
+type r<T> = {mutable v: [option<T>]};
-fn f[T]() -> [T] { ret ~[]; }
+fn f<T>() -> [T] { ret ~[]; }
fn main() { let r: r<int> = {mutable v: ~[]}; r.v = f(); }
import std::option::none;
import std::option::some;
-fn foo[T](y: &option::t<T>) {
+fn foo<T>(y: &option::t<T>) {
let x: int;
let rs: [int] = ~[];
/* tests that x doesn't get put in the precondition for the
-tag maybe[T] { nothing; just(T); }
+tag maybe<T> { nothing; just(T); }
fn foo(x: maybe<int>) {
alt x { nothing. { log_err "A"; } just(a) { log_err "B"; } }
// -*- rust -*-
-fn f[T, U](x: &T, y: &U) -> {a: T, b: U} { ret {a: x, b: y}; }
+fn f<T, U>(x: &T, y: &U) -> {a: T, b: U} { ret {a: x, b: y}; }
-fn main() { log f({x: 3, y: 4, z: 5}, 4).a.x; log f(5, 6).a; }
\ No newline at end of file
+fn main() { log f({x: 3, y: 4, z: 5}, 4).a.x; log f(5, 6).a; }
-fn f[T](x: &[T]) -> T { ret x.(0); }
+fn f<T>(x: &[T]) -> T { ret x.(0); }
fn g(act: fn(&[int]) -> int ) -> int { ret act(~[1, 2, 3]); }
fn main() {
- fn echo[T](c: int, x: fn(&T)) { log_err "wee"; }
+ fn echo<T>(c: int, x: fn(&T)) { log_err "wee"; }
let y = bind echo(42, _);
fn main() {
- fn echo[T](c: int, x: &[T]) { }
+ fn echo<T>(c: int, x: &[T]) { }
let y: fn(&[int]) = bind echo(42, _);
-fn iter_vec[T](v: &[T], f: &block(&T) ) { for x: T in v { f(x); } }
+fn iter_vec<T>(v: &[T], f: &block(&T) ) { for x: T in v { f(x); } }
fn main() {
let v = ~[1, 2, 3, 4, 5, 6, 7];
-fn iter_vec[T](v: &[T], f: &block(&T) ) { for x: T in v { f(x); } }
+fn iter_vec<T>(v: &[T], f: &block(&T) ) { for x: T in v { f(x); } }
fn main() {
let v = ~[1, 2, 3, 4, 5];
-type box[T] = {c: @T};
+type box<T> = {c: @T};
-fn unbox[T](b: &box<T>) -> T { ret *b.c; }
+fn unbox<T>(b: &box<T>) -> T { ret *b.c; }
fn main() {
let foo: int = 17;
-fn f[T](i: @int, t: &T) { }
+fn f<T>(i: @int, t: &T) { }
-fn main() { let x = bind f[char](@0xdeafbeef, _); }
\ No newline at end of file
+fn main() { let x = bind f[char](@0xdeafbeef, _); }
export foo;
export main;
-tag list_cell[T] { cons(@list_cell<T>); }
+tag list_cell<T> { cons(@list_cell<T>); }
fn main() { }
// -*- rust -*-
-type compare[T] = fn(@T, @T) -> bool ;
+type compare<T> = fn(@T, @T) -> bool ;
-fn test_generic[T](expected: @T, eq: &compare<T>) {
+fn test_generic<T>(expected: @T, eq: &compare<T>) {
let actual: @T = alt true { true { expected } };
assert (eq(expected, actual));
}
// -*- rust -*-
-type compare[T] = fn(&T, &T) -> bool ;
+type compare<T> = fn(&T, &T) -> bool ;
-fn test_generic[T](expected: &T, eq: &compare<T>) {
+fn test_generic<T>(expected: &T, eq: &compare<T>) {
let actual: T = alt true { true { expected } };
assert (eq(expected, actual));
}
// -*- rust -*-
-type compare[T] = fn(&T, &T) -> bool ;
+type compare<T> = fn(&T, &T) -> bool ;
-fn test_generic[T](expected: &T, eq: &compare<T>) {
+fn test_generic<T>(expected: &T, eq: &compare<T>) {
let actual: T = alt true { true { expected } };
assert (eq(expected, actual));
}
// -*- rust -*-
-type compare[T] = fn(@T, @T) -> bool ;
+type compare<T> = fn(@T, @T) -> bool ;
-fn test_generic[T](expected: @T, eq: &compare<T>) {
+fn test_generic<T>(expected: @T, eq: &compare<T>) {
let actual: @T = { expected };
assert (eq(expected, actual));
}
// -*- rust -*-
-type compare[T] = fn(&T, &T) -> bool ;
+type compare<T> = fn(&T, &T) -> bool ;
-fn test_generic[T](expected: &T, eq: &compare<T>) {
+fn test_generic<T>(expected: &T, eq: &compare<T>) {
let actual: T = { expected };
assert (eq(expected, actual));
}
// -*- rust -*-
// Tests for standalone blocks as expressions with dynamic type sizes
-type compare[T] = fn(&T, &T) -> bool ;
+type compare<T> = fn(&T, &T) -> bool ;
-fn test_generic[T](expected: &T, eq: &compare<T>) {
+fn test_generic<T>(expected: &T, eq: &compare<T>) {
let actual: T = { expected };
assert (eq(expected, actual));
}
}
fn test_generic() {
- fn f[T](t: &T) -> T { t }
+ fn f<T>(t: &T) -> T { t }
assert (f(10) == 10);
}
// -*- rust -*-
-type compare[T] = fn(@T, @T) -> bool ;
+type compare<T> = fn(@T, @T) -> bool ;
-fn test_generic[T](expected: @T, not_expected: @T, eq: &compare<T>) {
+fn test_generic<T>(expected: @T, not_expected: @T, eq: &compare<T>) {
let actual: @T = if true { expected } else { not_expected };
assert (eq(expected, actual));
}
// -*- rust -*-
-type compare[T] = fn(&T, &T) -> bool ;
+type compare<T> = fn(&T, &T) -> bool ;
-fn test_generic[T](expected: &T, not_expected: &T, eq: &compare<T>) {
+fn test_generic<T>(expected: &T, not_expected: &T, eq: &compare<T>) {
let actual: T = if true { expected } else { not_expected };
assert (eq(expected, actual));
}
// -*- rust -*-
// Tests for if as expressions with dynamic type sizes
-type compare[T] = fn(&T, &T) -> bool ;
+type compare<T> = fn(&T, &T) -> bool ;
-fn test_generic[T](expected: &T, not_expected: &T, eq: &compare<T>) {
+fn test_generic<T>(expected: &T, not_expected: &T, eq: &compare<T>) {
let actual: T = if true { expected } else { not_expected };
assert (eq(expected, actual));
}
-fn fix_help[A, B](f: @fn(@fn(&A) -> B , &A) -> B , x: &A) -> B {
+fn fix_help<A, B>(f: @fn(@fn(&A) -> B , &A) -> B , x: &A) -> B {
ret f(@bind fix_help(f, _), x);
}
-fn fix[A, B](f: @fn(@fn(&A) -> B , &A) -> B ) -> @fn(&A) -> B {
+fn fix<A, B>(f: @fn(@fn(&A) -> B , &A) -> B ) -> @fn(&A) -> B {
ret @bind fix_help(f, _);
}
let fact = fix(@fact_);
assert (fact(5) == 120);
assert (fact(2) == 2);
-}
\ No newline at end of file
+}
-obj ob[K](k: K) {
+obj ob<K>(k: K) {
iter foo() -> @{a: K} { put @{a: k}; }
}
-fn id[T](t: &T) -> T { ret t; }
+fn id<T>(t: &T) -> T { ret t; }
fn main() {
let expected = @100;
let actual = id[@int](expected);
log *actual;
assert (*expected == *actual);
-}
\ No newline at end of file
+}
-fn id[T](t: &T) -> T { ret t; }
+fn id<T>(t: &T) -> T { ret t; }
fn main() {
let t = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7};
assert (t.f == 6);
let f0 = bind id(t);
assert (f0().f == 6);
-}
\ No newline at end of file
+}
-fn id[T](t: &T) -> T { ret t; }
+fn id<T>(t: &T) -> T { ret t; }
fn main() {
let t = {_0: 1, _1: 2, _2: 3, _3: 4, _4: 5, _5: 6, _6: 7};
_5: int,
_6: int}](_);
assert (f1(t)._5 == 6);
-}
\ No newline at end of file
+}
-fn box[T](x: &{x: T, y: T, z: T}) -> @{x: T, y: T, z: T} { ret @x; }
+fn box<T>(x: &{x: T, y: T, z: T}) -> @{x: T, y: T, z: T} { ret @x; }
fn main() {
let x: @{x: int, y: int, z: int} = box[int]({x: 1, y: 2, z: 3});
assert (x.y == 2);
-}
\ No newline at end of file
+}
-fn g[X](x: &X) -> X { ret x; }
+fn g<X>(x: &X) -> X { ret x; }
-fn f[T](t: &T) -> {a: T, b: T} {
+fn f<T>(t: &T) -> {a: T, b: T} {
type pair = {a: T, b: T};
let x: pair = {a: t, b: t};
log b.b;
assert (b.a == 10);
assert (b.b == 10);
-}
\ No newline at end of file
+}
-fn f[T](t: &T) { let t1: T = t; }
+fn f<T>(t: &T) { let t1: T = t; }
-fn main() { let x = {x: @10, y: @12}; f(x); }
\ No newline at end of file
+fn main() { let x = {x: @10, y: @12}; f(x); }
-type recbox[T] = {x: @T};
+type recbox<T> = {x: @T};
-fn reclift[T](t: &T) -> recbox<T> { ret {x: @t}; }
+fn reclift<T>(t: &T) -> recbox<T> { ret {x: @t}; }
fn main() {
let foo: int = 17;
-fn f[T](x: @T) -> @T { ret x; }
+fn f<T>(x: @T) -> @T { ret x; }
-fn main() { let x = f(@3); log *x; }
\ No newline at end of file
+fn main() { let x = f(@3); log *x; }
// -*- rust -*-
// Issue #45: infer type parameters in function applications
-fn id[T](x: &T) -> T { ret x; }
+fn id<T>(x: &T) -> T { ret x; }
-fn main() { let x: int = 42; let y: int = id(x); assert (x == y); }
\ No newline at end of file
+fn main() { let x: int = 42; let y: int = id(x); assert (x == y); }
// -*- rust -*-
mod foomod {
- fn foo[T]() { }
+ fn foo<T>() { }
}
-fn main() { foomod::foo[int](); foomod::foo[int](); }
\ No newline at end of file
+fn main() { foomod::foo[int](); foomod::foo[int](); }
// -*- rust -*-
-fn id[T](x: &T) -> T { ret x; }
+fn id<T>(x: &T) -> T { ret x; }
type triple = {x: int, y: int, z: int};
y = q.z;
log y;
assert (x == y);
-}
\ No newline at end of file
+}
// Contrived example? No. It showed up in rustc's resolve pass.
iter i() { put (); }
-fn foo[T](t: &T) { let x: int = 10; for each j: () in i() { log x; } }
+fn foo<T>(t: &T) { let x: int = 10; for each j: () in i() { log x; } }
fn main() { foo(0xdeadbeef_u); }
-tag wrapper[T] { wrapped(T); }
+tag wrapper<T> { wrapped(T); }
fn main() { let w = wrapped(~[1, 2, 3, 4, 5]); }
-fn f[T](v: @T) { }
+fn f<T>(v: @T) { }
fn main() { f(@~[1, 2, 3, 4, 5]); }
-obj handle[T](data: T) {
+obj handle<T>(data: T) {
fn get() -> T { ret data; }
}
-obj buf[T](data: {_0: T, _1: T, _2: T}) {
+obj buf<T>(data: {_0: T, _1: T, _2: T}) {
fn get(i: int) -> T {
if i == 0 {
ret data._0;
-tag list[T] { cons(@T, @list<T>); nil; }
+tag list<T> { cons(@T, @list<T>); nil; }
fn main() {
let a: list<int> =
-tag foo[T] { arm(T); }
+tag foo<T> { arm(T); }
-fn altfoo[T](f: &foo<T>) {
+fn altfoo<T>(f: &foo<T>) {
let hit = false;
alt f { arm[T](x) { log "in arm"; hit = true; } }
assert (hit);
// This causes memory corruption in stage0.
-tag thing[K] { some(K); }
+tag thing<K> { some(K); }
-fn main() { let x = some("hi"); }
\ No newline at end of file
+fn main() { let x = some("hi"); }
-tag clam[T] { a(T); }
+tag clam<T> { a(T); }
-fn main() { let c = a(3); }
\ No newline at end of file
+fn main() { let c = a(3); }
// -*- rust -*-
-tag noption[T] { some(T); }
+tag noption<T> { some(T); }
fn main() {
let nop: noption<int> = some[int](5);
-tag option[T] { some(@T); none; }
+tag option<T> { some(@T); none; }
fn main() { let a: option<int> = some[int](@10); a = none[int]; }
fn chk(a: &int) { log a; assert (a == 1); }
-fn apply[T](produce: fn() -> T , consume: fn(&T) ) { consume(produce()); }
+fn apply<T>(produce: fn() -> T , consume: fn(&T) ) { consume(produce()); }
fn main() {
let produce: fn() -> int = mk;
let consume: fn(&int) = chk;
apply[int](produce, consume);
-}
\ No newline at end of file
+}
-fn get_third[T](t: &(T, T, T)) -> T {
+fn get_third<T>(t: &(T, T, T)) -> T {
let (_, _, x) = t;
ret x;
}
log get_third((1, 2, 3));
assert (get_third((1, 2, 3)) == 3);
assert (get_third((5u8, 6u8, 7u8)) == 7u8);
-}
\ No newline at end of file
+}
-type foo[T] = {a: T};
+type foo<T> = {a: T};
-type bar[T] = foo<T>;
+type bar<T> = foo<T>;
-fn takebar[T](b: &bar<T>) { }
+fn takebar<T>(b: &bar<T>) { }
fn main() { }
-type pair[T] = {x: T, y: T};
+type pair<T> = {x: T, y: T};
fn main() {
let x: pair<int> = {x: 10, y: 12};
import rusti::ivec_len;
native "rust-intrinsic" mod rusti {
- fn ivec_len[T](v: &[T]) -> uint;
+ fn ivec_len<T>(v: &[T]) -> uint;
}
fn main() {
-fn quux[T](x: &T) -> T { let f = id[T]; ret f(x); }
+fn quux<T>(x: &T) -> T { let f = id[T]; ret f(x); }
-fn id[T](x: &T) -> T { ret x; }
+fn id<T>(x: &T) -> T { ret x; }
-fn main() { assert (quux(10) == 10); }
\ No newline at end of file
+fn main() { assert (quux(10) == 10); }
-fn double[T](a: &T) -> [T] { ret ~[a] + ~[a]; }
+fn double<T>(a: &T) -> [T] { ret ~[a] + ~[a]; }
fn double_int(a: int) -> [int] { ret ~[a] + ~[a]; }
-fn leaky[T](t: &T) { }
+fn leaky<T>(t: &T) { }
-fn main() { let x = @10; leaky[@int](x); }
\ No newline at end of file
+fn main() { let x = @10; leaky[@int](x); }
-tag myvec[X] = [X];
+tag myvec<X> = [X];
-fn myvec_deref[X](mv: &myvec<X>) -> [X] { ret *mv; }
+fn myvec_deref<X>(mv: &myvec<X>) -> [X] { ret *mv; }
-fn myvec_elt[X](mv: &myvec<X>) -> X { ret mv.(0); }
+fn myvec_elt<X>(mv: &myvec<X>) -> X { ret mv.(0); }
fn main() {
let mv = myvec(~[1, 2, 3]);
// -*- rust -*-
-tag clam[T] { signed(int); unsigned(uint); }
+tag clam<T> { signed(int); unsigned(uint); }
-fn getclam[T]() -> clam<T> { ret signed[T](42); }
+fn getclam<T>() -> clam<T> { ret signed[T](42); }
-obj impatience[T]() {
+obj impatience<T>() {
fn moreclam() -> clam<T> { be getclam[T](); }
}
-resource finish[T](arg: {val: T, fin: fn(&T) }) { arg.fin(arg.val); }
+resource finish<T>(arg: {val: T, fin: fn(&T) }) { arg.fin(arg.val); }
fn main() {
let box = @mutable 10;
{ let i <- finish({val: box, fin: dec_box}); }
assert (*box == 9);
-}
\ No newline at end of file
+}
*i = false;
}
-tag option[T] { none; some(T); }
+tag option<T> { none; some(T); }
fn sink(res: option<close_res>) {}
-tag option[T] { none; some(T); }
+tag option<T> { none; some(T); }
-fn f[T]() -> option<T> { ret none; }
+fn f<T>() -> option<T> { ret none; }
fn main() { f[int](); }
import std::comm::mk_port;
// tests that ctrl's type gets inferred properly
-type command[K, V] = {key: K, val: V};
+type command<K, V> = {key: K, val: V};
-fn cache_server[K, V](c: _chan<_chan<command<K, V>>>) {
+fn cache_server<K, V>(c: _chan<_chan<command<K, V>>>) {
let ctrl = mk_port[_chan<command<K, V>>]();
send(c, ctrl.mk_chan());
}
}
}
-tag t[T] { none; some(T); }
+tag t<T> { none; some(T); }
fn main() {
let x = 10;
-tag opt[T] { none; }
+tag opt<T> { none; }
-fn main() { let x = none[int]; alt x { none[int]. { log "hello world"; } } }
\ No newline at end of file
+fn main() { let x = none[int]; alt x { none[int]. { log "hello world"; } } }
-tag clam[T] { a(T); }
+tag clam<T> { a(T); }
-fn main() { let c = a(2); alt c { a[int](_) { } } }
\ No newline at end of file
+fn main() { let c = a(2); alt c { a[int](_) { } } }
-tag clam[T] { a(T); }
+tag clam<T> { a(T); }
-fn main() { }
\ No newline at end of file
+fn main() { }
// -*- rust -*-
-tag clam[T] { a(T, int); b; }
+tag clam<T> { a(T, int); b; }
-fn uhoh[T](v: &[clam<T>]) {
+fn uhoh<T>(v: &[clam<T>]) {
alt v.(1) {
a[T](t, u) { log "incorrect"; log u; fail; }
b[T]. { log "correct"; }
-fn swap[@T](v: &[mutable T], i: int, j: int) { v.(i) <-> v.(j); }
+fn swap<@T>(v: &[mutable T], i: int, j: int) { v.(i) <-> v.(j); }
fn main() {
let a: [mutable int] = ~[mutable 0, 1, 2, 3, 4, 5, 6];
tag colour { red; green; }
-obj foo[T]() {
+obj foo<T>() {
fn meth(x: &T) { }
}
-fn main() { foo[colour]().meth(red); }
\ No newline at end of file
+fn main() { foo[colour]().meth(red); }
-fn p_foo[T](pinned: &T) { }
-fn s_foo[@T](shared: &T) { }
-fn u_foo[~T](unique: &T) { }
+fn p_foo<T>(pinned: &T) { }
+fn s_foo<@T>(shared: &T) { }
+fn u_foo<~T>(unique: &T) { }
resource r(i: int) { }
//u_foo(~10);
u_foo(10);
-}
\ No newline at end of file
+}
-type lteq[T] = fn(&T) -> bool ;
+type lteq<T> = fn(&T) -> bool ;
fn main(args: [str]) { }
while lo_ < hi { put lo_; lo_ += 1u; }
}
-fn create_index[T](index: &[{a: T, b: uint}], hash_fn: fn(&T) -> uint ) {
+fn create_index<T>(index: &[{a: T, b: uint}], hash_fn: fn(&T) -> uint ) {
for each i: uint in range(0u, 256u) { let bucket: [T] = ~[]; }
}
use std;
import std::unsafe;
-fn null[T]() -> *T { unsafe::reinterpret_cast(0) }
+fn null<T>() -> *T { unsafe::reinterpret_cast(0) }
fn main() {
null[int]();
-}
\ No newline at end of file
+}
-fn foo[T](o: &myoption<T>) -> int {
+fn foo<T>(o: &myoption<T>) -> int {
let x: int = 5;
alt o { none[T]. { } some[T](t) { x += 1; } }
ret x;
}
-tag myoption[T] { none; some(T); }
+tag myoption<T> { none; some(T); }
fn main() { log 5; }
-fn foo[T](o: &myoption<T>) -> int {
+fn foo<T>(o: &myoption<T>) -> int {
let x: int;
alt o { none[T]. { fail; } some[T](t) { x = 5; } }
ret x;
}
-tag myoption[T] { none; some(T); }
+tag myoption<T> { none; some(T); }
fn main() { log 5; }
-fn push[T](v: &mutable [mutable? T], t: &T) { v += ~[t]; }
+fn push<T>(v: &mutable [mutable? T], t: &T) { v += ~[t]; }
fn main() { let v = ~[1, 2, 3]; push(v, 1); }
assert (deq.get(3) == d);
}
-type eqfn[T] = fn(&T, &T) -> bool ;
+type eqfn<T> = fn(&T, &T) -> bool ;
-fn test_parameterized[@T](e: eqfn<T>, a: &T, b: &T, c: &T, d: &T) {
+fn test_parameterized<@T>(e: eqfn<T>, a: &T, b: &T, c: &T, d: &T) {
let deq: deque::t<T> = deque::create[T]();
assert (deq.size() == 0u);
deq.add_front(a);
tag taggy { one(int); two(int, int); three(int, int, int); }
-tag taggypar[@T] { onepar(int); twopar(int, int); threepar(int, int, int); }
+tag taggypar<@T> { onepar(int); twopar(int, int); threepar(int, int, int); }
type reccy = {x: int, y: int, t: taggy};
}
}
}
- fn taggypareq[@T](a: &taggypar<T>, b: &taggypar<T>) -> bool {
+ fn taggypareq<@T>(a: &taggypar<T>, b: &taggypar<T>) -> bool {
alt a {
onepar[T](a1) {
alt b { onepar[T](b1) { ret a1 == b1; } _ { ret false; } }