1
Fork 0

stdlib: Remove unneeded type params from alt patterns

This commit is contained in:
Brian Anderson 2011-05-31 00:13:37 -04:00
parent c1d97a41eb
commit ed0eb8f45a
9 changed files with 55 additions and 55 deletions

View file

@ -48,7 +48,7 @@ fn create[T]() -> t[T] {
fn get[T](vec[cell[T]] elts, uint i) -> T { fn get[T](vec[cell[T]] elts, uint i) -> T {
ret alt (elts.(i)) { ret alt (elts.(i)) {
case (option::some[T](?t)) { t } case (option::some(?t)) { t }
case (_) { fail } case (_) { fail }
}; };
} }

View file

@ -63,8 +63,8 @@ fn maybe_get_doc(doc d, uint tg) -> option::t[doc] {
fn get_doc(doc d, uint tg) -> doc { fn get_doc(doc d, uint tg) -> doc {
alt (maybe_get_doc(d, tg)) { alt (maybe_get_doc(d, tg)) {
case (some[doc](?d)) {ret d;} case (some(?d)) {ret d;}
case (none[doc]) { case (none) {
log_err "failed to find block with tag " + uint::to_str(tg, 10u); log_err "failed to find block with tag " + uint::to_str(tg, 10u);
fail; fail;
} }

View file

@ -130,10 +130,10 @@ mod ct {
auto n = (c - ('0' as u8)) as uint; auto n = (c - ('0' as u8)) as uint;
ret alt (peek_num(s, i + 1u, lim)) { ret alt (peek_num(s, i + 1u, lim)) {
case (none[tup(uint, uint)]) { case (none) {
some[tup(uint, uint)](tup(n, i + 1u)) some[tup(uint, uint)](tup(n, i + 1u))
} }
case (some[tup(uint, uint)](?next)) { case (some(?next)) {
auto m = next._0; auto m = next._0;
auto j = next._1; auto j = next._1;
some[tup(uint, uint)](tup(n * 10u + m, j)) some[tup(uint, uint)](tup(n * 10u + m, j))
@ -162,10 +162,10 @@ mod ct {
auto num = peek_num(s, i, lim); auto num = peek_num(s, i, lim);
ret alt (num) { ret alt (num) {
case (none[tup(uint, uint)]) { case (none) {
tup(none[int], i) tup(none[int], i)
} }
case (some[tup(uint, uint)](?t)) { case (some(?t)) {
auto n = t._0; auto n = t._0;
auto j = t._1; auto j = t._1;
if (j < lim && s.(j) == '$' as u8) { if (j < lim && s.(j) == '$' as u8) {
@ -218,20 +218,20 @@ mod ct {
auto param = parse_parameter(s, i + 1u, lim); auto param = parse_parameter(s, i + 1u, lim);
auto j = param._1; auto j = param._1;
alt (param._0) { alt (param._0) {
case (none[int]) { case (none) {
tup(count_is_next_param, j) tup(count_is_next_param, j)
} }
case (some[int](?n)) { case (some(?n)) {
tup(count_is_param(n), j) tup(count_is_param(n), j)
} }
} }
} else { } else {
auto num = peek_num(s, i, lim); auto num = peek_num(s, i, lim);
alt (num) { alt (num) {
case (none[tup(uint, uint)]) { case (none) {
tup(count_implied, i) tup(count_implied, i)
} }
case (some[tup(uint, uint)](?num)) { case (some(?num)) {
tup(count_is(num._0 as int), num._1) tup(count_is(num._0 as int), num._1)
} }
} }

View file

@ -175,8 +175,8 @@ fn getopts(vec[str] args, vec[opt] opts) -> result {
name_pos += 1u; name_pos += 1u;
auto optid; auto optid;
alt (find_opt(opts, nm)) { alt (find_opt(opts, nm)) {
case (some[uint](?id)) {optid = id;} case (some(?id)) {optid = id;}
case (none[uint]) { case (none) {
ret failure(unrecognized_option(name_str(nm))); ret failure(unrecognized_option(name_str(nm)));
} }
} }
@ -234,8 +234,8 @@ fn getopts(vec[str] args, vec[opt] opts) -> result {
fn opt_vals(match m, str nm) -> vec[optval] { fn opt_vals(match m, str nm) -> vec[optval] {
ret alt (find_opt(m.opts, mkname(nm))) { ret alt (find_opt(m.opts, mkname(nm))) {
case (some[uint](?id)) { m.vals.(id) } case (some(?id)) { m.vals.(id) }
case (none[uint]) { case (none) {
log_err "No option '" + nm + "' defined."; log_err "No option '" + nm + "' defined.";
fail fail
} }

View file

@ -23,11 +23,11 @@ fn from_vec[T](vec[T] v) -> list[T] {
fn foldl[T,U](&list[T] ls, &U u, fn(&T t, &U u) -> U f) -> U { fn foldl[T,U](&list[T] ls, &U u, fn(&T t, &U u) -> U f) -> U {
alt(ls) { alt(ls) {
case (cons[T](?hd, ?tl)) { case (cons(?hd, ?tl)) {
auto u_ = f(hd, u); auto u_ = f(hd, u);
be foldl[T,U](*tl, u_, f); be foldl[T,U](*tl, u_, f);
} }
case (nil[T]) { case (nil) {
ret u; ret u;
} }
} }
@ -36,17 +36,17 @@ fn foldl[T,U](&list[T] ls, &U u, fn(&T t, &U u) -> U f) -> U {
fn find[T,U](&list[T] ls, fn find[T,U](&list[T] ls,
(fn(&T) -> option::t[U]) f) -> option::t[U] { (fn(&T) -> option::t[U]) f) -> option::t[U] {
alt(ls) { alt(ls) {
case (cons[T](?hd, ?tl)) { case (cons(?hd, ?tl)) {
alt (f(hd)) { alt (f(hd)) {
case (none[U]) { case (none) {
be find[T,U](*tl, f); be find[T,U](*tl, f);
} }
case (some[U](?res)) { case (some(?res)) {
ret some[U](res); ret some[U](res);
} }
} }
} }
case (nil[T]) { case (nil) {
ret none[U]; ret none[U];
} }
} }
@ -54,14 +54,14 @@ fn find[T,U](&list[T] ls,
fn has[T](&list[T] ls, &T elt) -> bool { fn has[T](&list[T] ls, &T elt) -> bool {
alt(ls) { alt(ls) {
case (cons[T](?hd, ?tl)) { case (cons(?hd, ?tl)) {
if (elt == hd) { if (elt == hd) {
ret true; ret true;
} else { } else {
be has(*tl, elt); be has(*tl, elt);
} }
} }
case (nil[T]) { ret false; } case (nil) { ret false; }
} }
} }
@ -74,22 +74,22 @@ fn length[T](&list[T] ls) -> uint {
fn cdr[T](&list[T] ls) -> list[T] { fn cdr[T](&list[T] ls) -> list[T] {
alt (ls) { alt (ls) {
case (cons[T](_, ?tl)) {ret *tl;} case (cons(_, ?tl)) {ret *tl;}
} }
} }
fn car[T](&list[T] ls) -> T { fn car[T](&list[T] ls) -> T {
alt (ls) { alt (ls) {
case (cons[T](?hd, _)) {ret hd;} case (cons(?hd, _)) {ret hd;}
} }
} }
fn append[T](&list[T] l, &list[T] m) -> list[T] { fn append[T](&list[T] l, &list[T] m) -> list[T] {
alt (l) { alt (l) {
case (nil[T]) { case (nil) {
ret m; ret m;
} }
case (cons[T](?x, ?xs)) { case (cons(?x, ?xs)) {
let list[T] rest = append[T](*xs, m); let list[T] rest = append[T](*xs, m);
ret cons[T](x, @rest); ret cons[T](x, @rest);
} }

View file

@ -75,7 +75,7 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
while (i < nbkts) { while (i < nbkts) {
let uint j = hash(h, nbkts, i); let uint j = hash(h, nbkts, i);
alt (bkts.(j)) { alt (bkts.(j)) {
case (some[K, V](?k, _)) { case (some(?k, _)) {
if (eqer(key, k)) { if (eqer(key, k)) {
bkts.(j) = some[K, V](k, val); bkts.(j) = some[K, V](k, val);
ret false; ret false;
@ -103,12 +103,12 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
while (i < nbkts) { while (i < nbkts) {
let uint j = (hash(h, nbkts, i)); let uint j = (hash(h, nbkts, i));
alt (bkts.(j)) { alt (bkts.(j)) {
case (some[K, V](?k, ?v)) { case (some(?k, ?v)) {
if (eqer(key, k)) { if (eqer(key, k)) {
ret option::some[V](v); ret option::some[V](v);
} }
} }
case (nil[K, V]) { case (nil) {
ret option::none[V]; ret option::none[V];
} }
case (deleted[K, V]) { } case (deleted[K, V]) { }
@ -126,7 +126,7 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
{ {
for (bucket[K, V] b in oldbkts) { for (bucket[K, V] b in oldbkts) {
alt (b) { alt (b) {
case (some[K, V](?k, ?v)) { case (some(?k, ?v)) {
insert_common[K, V](hasher, eqer, newbkts, insert_common[K, V](hasher, eqer, newbkts,
nnewbkts, k, v); nnewbkts, k, v);
} }
@ -167,14 +167,14 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
fn contains_key(&K key) -> bool { fn contains_key(&K key) -> bool {
ret alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) { ret alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) {
case (option::some[V](_)) { true } case (option::some(_)) { true }
case (_) { false } case (_) { false }
}; };
} }
fn get(&K key) -> V { fn get(&K key) -> V {
ret alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) { ret alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) {
case (option::some[V](?val)) { val } case (option::some(?val)) { val }
case (_) { fail } case (_) { fail }
}; };
} }
@ -189,15 +189,15 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
while (i < nbkts) { while (i < nbkts) {
let uint j = (hash(h, nbkts, i)); let uint j = (hash(h, nbkts, i));
alt (bkts.(j)) { alt (bkts.(j)) {
case (some[K, V](?k, ?v)) { case (some(?k, ?v)) {
if (eqer(key, k)) { if (eqer(key, k)) {
bkts.(j) = deleted[K, V]; bkts.(j) = deleted[K, V];
nelts -= 1u; nelts -= 1u;
ret option::some[V](v); ret option::some[V](v);
} }
} }
case (deleted[K, V]) { } case (deleted) { }
case (nil[K, V]) { case (nil) {
ret option::none[V]; ret option::none[V];
} }
} }
@ -216,7 +216,7 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
iter items() -> @tup(K,V) { iter items() -> @tup(K,V) {
for (bucket[K,V] b in bkts) { for (bucket[K,V] b in bkts) {
alt (b) { alt (b) {
case(some[K,V](?k,?v)) { case(some(?k,?v)) {
put @tup(k,v); put @tup(k,v);
} }
case (_) { } case (_) { }

View file

@ -9,10 +9,10 @@ type operator[T, U] = fn(&T) -> U;
fn get[T](&t[T] opt) -> T { fn get[T](&t[T] opt) -> T {
ret alt (opt) { ret alt (opt) {
case (some[T](?x)) { case (some(?x)) {
x x
} }
case (none[T]) { case (none) {
fail fail
} }
}; };
@ -20,10 +20,10 @@ fn get[T](&t[T] opt) -> T {
fn map[T, U](&operator[T, U] f, &t[T] opt) -> t[U] { fn map[T, U](&operator[T, U] f, &t[T] opt) -> t[U] {
ret alt (opt) { ret alt (opt) {
case (some[T](?x)) { case (some(?x)) {
some[U](f(x)) some[U](f(x))
} }
case (none[T]) { case (none) {
none[U] none[U]
} }
}; };
@ -31,8 +31,8 @@ fn map[T, U](&operator[T, U] f, &t[T] opt) -> t[U] {
fn is_none[T](&t[T] opt) -> bool { fn is_none[T](&t[T] opt) -> bool {
ret alt (opt) { ret alt (opt) {
case (none[T]) { true } case (none) { true }
case (some[T](_)) { false } case (some(_)) { false }
}; };
} }
@ -43,16 +43,16 @@ fn from_maybe[T](&T def, &t[T] opt) -> T {
fn maybe[T, U](&U def, fn(&T) -> U f, &t[T] opt) -> U { fn maybe[T, U](&U def, fn(&T) -> U f, &t[T] opt) -> U {
ret alt (opt) { ret alt (opt) {
case (none[T]) { def } case (none) { def }
case (some[T](?t)) { f(t) } case (some(?t)) { f(t) }
}; };
} }
// Can be defined in terms of the above when/if we have const bind. // Can be defined in terms of the above when/if we have const bind.
fn may[T](fn(&T) f, &t[T] opt) { fn may[T](fn(&T) f, &t[T] opt) {
alt (opt) { alt (opt) {
case (none[T]) { /* nothing */ } case (none) { /* nothing */ }
case (some[T](?t)) { f(t); } case (some(?t)) { f(t); }
} }
} }

View file

@ -22,8 +22,8 @@ fn make_set(&ufind ufnd) -> uint {
fn find(&ufind ufnd, uint n) -> uint { fn find(&ufind ufnd, uint n) -> uint {
alt (ufnd.nodes.(n)) { alt (ufnd.nodes.(n)) {
case (none[uint]) { ret n; } case (none) { ret n; }
case (some[uint](?m)) { be find(ufnd, m); } case (some(?m)) { be find(ufnd, m); }
} }
} }

View file

@ -233,8 +233,8 @@ fn filter_map[T, U](&fn(&T) -> option::t[U] f, &array[T] v) -> vec[U] {
let vec[U] res = []; //TODO does this work these days? let vec[U] res = []; //TODO does this work these days?
for(T ve in v) { for(T ve in v) {
alt(f(ve)) { alt(f(ve)) {
case (some[U](?elt)) { res += [elt]; } case (some(?elt)) { res += [elt]; }
case (none[U]) {} case (none) {}
} }
} }
ret res; ret res;
@ -305,8 +305,8 @@ fn clone[T](&vec[T] v) -> vec[T] {
fn plus_option[T](&vec[T] v, &option::t[T] o) -> () { fn plus_option[T](&vec[T] v, &option::t[T] o) -> () {
alt (o) { alt (o) {
case (none[T]) {} case (none) {}
case (some[T](?x)) { v += [x]; } case (some(?x)) { v += [x]; }
} }
} }
@ -315,8 +315,8 @@ fn cat_options[T](&vec[option::t[T]] v) -> vec[T] {
for (option::t[T] o in v) { for (option::t[T] o in v) {
alt (o) { alt (o) {
case (none[T]) { } case (none) { }
case (some[T](?t)) { case (some(?t)) {
res += [t]; res += [t];
} }
} }