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 {
ret alt (elts.(i)) {
case (option::some[T](?t)) { t }
case (option::some(?t)) { t }
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 {
alt (maybe_get_doc(d, tg)) {
case (some[doc](?d)) {ret d;}
case (none[doc]) {
case (some(?d)) {ret d;}
case (none) {
log_err "failed to find block with tag " + uint::to_str(tg, 10u);
fail;
}

View file

@ -130,10 +130,10 @@ mod ct {
auto n = (c - ('0' as u8)) as uint;
ret alt (peek_num(s, i + 1u, lim)) {
case (none[tup(uint, uint)]) {
case (none) {
some[tup(uint, uint)](tup(n, i + 1u))
}
case (some[tup(uint, uint)](?next)) {
case (some(?next)) {
auto m = next._0;
auto j = next._1;
some[tup(uint, uint)](tup(n * 10u + m, j))
@ -162,10 +162,10 @@ mod ct {
auto num = peek_num(s, i, lim);
ret alt (num) {
case (none[tup(uint, uint)]) {
case (none) {
tup(none[int], i)
}
case (some[tup(uint, uint)](?t)) {
case (some(?t)) {
auto n = t._0;
auto j = t._1;
if (j < lim && s.(j) == '$' as u8) {
@ -218,20 +218,20 @@ mod ct {
auto param = parse_parameter(s, i + 1u, lim);
auto j = param._1;
alt (param._0) {
case (none[int]) {
case (none) {
tup(count_is_next_param, j)
}
case (some[int](?n)) {
case (some(?n)) {
tup(count_is_param(n), j)
}
}
} else {
auto num = peek_num(s, i, lim);
alt (num) {
case (none[tup(uint, uint)]) {
case (none) {
tup(count_implied, i)
}
case (some[tup(uint, uint)](?num)) {
case (some(?num)) {
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;
auto optid;
alt (find_opt(opts, nm)) {
case (some[uint](?id)) {optid = id;}
case (none[uint]) {
case (some(?id)) {optid = id;}
case (none) {
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] {
ret alt (find_opt(m.opts, mkname(nm))) {
case (some[uint](?id)) { m.vals.(id) }
case (none[uint]) {
case (some(?id)) { m.vals.(id) }
case (none) {
log_err "No option '" + nm + "' defined.";
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 {
alt(ls) {
case (cons[T](?hd, ?tl)) {
case (cons(?hd, ?tl)) {
auto u_ = f(hd, u);
be foldl[T,U](*tl, u_, f);
}
case (nil[T]) {
case (nil) {
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(&T) -> option::t[U]) f) -> option::t[U] {
alt(ls) {
case (cons[T](?hd, ?tl)) {
case (cons(?hd, ?tl)) {
alt (f(hd)) {
case (none[U]) {
case (none) {
be find[T,U](*tl, f);
}
case (some[U](?res)) {
case (some(?res)) {
ret some[U](res);
}
}
}
case (nil[T]) {
case (nil) {
ret none[U];
}
}
@ -54,14 +54,14 @@ fn find[T,U](&list[T] ls,
fn has[T](&list[T] ls, &T elt) -> bool {
alt(ls) {
case (cons[T](?hd, ?tl)) {
case (cons(?hd, ?tl)) {
if (elt == hd) {
ret true;
} else {
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] {
alt (ls) {
case (cons[T](_, ?tl)) {ret *tl;}
case (cons(_, ?tl)) {ret *tl;}
}
}
fn car[T](&list[T] ls) -> T {
alt (ls) {
case (cons[T](?hd, _)) {ret hd;}
case (cons(?hd, _)) {ret hd;}
}
}
fn append[T](&list[T] l, &list[T] m) -> list[T] {
alt (l) {
case (nil[T]) {
case (nil) {
ret m;
}
case (cons[T](?x, ?xs)) {
case (cons(?x, ?xs)) {
let list[T] rest = append[T](*xs, m);
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) {
let uint j = hash(h, nbkts, i);
alt (bkts.(j)) {
case (some[K, V](?k, _)) {
case (some(?k, _)) {
if (eqer(key, k)) {
bkts.(j) = some[K, V](k, val);
ret false;
@ -103,12 +103,12 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
while (i < nbkts) {
let uint j = (hash(h, nbkts, i));
alt (bkts.(j)) {
case (some[K, V](?k, ?v)) {
case (some(?k, ?v)) {
if (eqer(key, k)) {
ret option::some[V](v);
}
}
case (nil[K, V]) {
case (nil) {
ret option::none[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) {
alt (b) {
case (some[K, V](?k, ?v)) {
case (some(?k, ?v)) {
insert_common[K, V](hasher, eqer, newbkts,
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 {
ret alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) {
case (option::some[V](_)) { true }
case (option::some(_)) { true }
case (_) { false }
};
}
fn get(&K key) -> V {
ret alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) {
case (option::some[V](?val)) { val }
case (option::some(?val)) { val }
case (_) { fail }
};
}
@ -189,15 +189,15 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
while (i < nbkts) {
let uint j = (hash(h, nbkts, i));
alt (bkts.(j)) {
case (some[K, V](?k, ?v)) {
case (some(?k, ?v)) {
if (eqer(key, k)) {
bkts.(j) = deleted[K, V];
nelts -= 1u;
ret option::some[V](v);
}
}
case (deleted[K, V]) { }
case (nil[K, V]) {
case (deleted) { }
case (nil) {
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) {
for (bucket[K,V] b in bkts) {
alt (b) {
case(some[K,V](?k,?v)) {
case(some(?k,?v)) {
put @tup(k,v);
}
case (_) { }

View file

@ -9,10 +9,10 @@ type operator[T, U] = fn(&T) -> U;
fn get[T](&t[T] opt) -> T {
ret alt (opt) {
case (some[T](?x)) {
case (some(?x)) {
x
}
case (none[T]) {
case (none) {
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] {
ret alt (opt) {
case (some[T](?x)) {
case (some(?x)) {
some[U](f(x))
}
case (none[T]) {
case (none) {
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 {
ret alt (opt) {
case (none[T]) { true }
case (some[T](_)) { false }
case (none) { true }
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 {
ret alt (opt) {
case (none[T]) { def }
case (some[T](?t)) { f(t) }
case (none) { def }
case (some(?t)) { f(t) }
};
}
// Can be defined in terms of the above when/if we have const bind.
fn may[T](fn(&T) f, &t[T] opt) {
alt (opt) {
case (none[T]) { /* nothing */ }
case (some[T](?t)) { f(t); }
case (none) { /* nothing */ }
case (some(?t)) { f(t); }
}
}

View file

@ -22,8 +22,8 @@ fn make_set(&ufind ufnd) -> uint {
fn find(&ufind ufnd, uint n) -> uint {
alt (ufnd.nodes.(n)) {
case (none[uint]) { ret n; }
case (some[uint](?m)) { be find(ufnd, m); }
case (none) { ret n; }
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?
for(T ve in v) {
alt(f(ve)) {
case (some[U](?elt)) { res += [elt]; }
case (none[U]) {}
case (some(?elt)) { res += [elt]; }
case (none) {}
}
}
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) -> () {
alt (o) {
case (none[T]) {}
case (some[T](?x)) { v += [x]; }
case (none) {}
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) {
alt (o) {
case (none[T]) { }
case (some[T](?t)) {
case (none) { }
case (some(?t)) {
res += [t];
}
}