diff options
| author | Marijn Haverbeke <[email protected]> | 2011-05-06 22:13:13 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <[email protected]> | 2011-05-06 22:51:19 +0200 |
| commit | a3ec0b1f643d00b9418e4884bd7caa07bf052201 (patch) | |
| tree | 82000510ac9c9cf3f0c7cf4ae5f3c6b123b559cb /src/lib/list.rs | |
| parent | Register new snapshots. (diff) | |
| download | rust-a3ec0b1f643d00b9418e4884bd7caa07bf052201.tar.xz rust-a3ec0b1f643d00b9418e4884bd7caa07bf052201.zip | |
Rename std modules to be camelcased
(Have fun mergining your stuff with this.)
Diffstat (limited to 'src/lib/list.rs')
| -rw-r--r-- | src/lib/list.rs | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/src/lib/list.rs b/src/lib/list.rs deleted file mode 100644 index 33f7c060..00000000 --- a/src/lib/list.rs +++ /dev/null @@ -1,66 +0,0 @@ -import option.some; -import option.none; - -// FIXME: It would probably be more appealing to define this as -// type list[T] = rec(T hd, option[@list[T]] tl), but at the moment -// our recursion rules do not permit that. - -tag list[T] { - cons(T, @list[T]); - nil; -} - -fn foldl[T,U](&list[T] ls, &U u, fn(&T t, &U u) -> U f) -> U { - alt(ls) { - case (cons[T](?hd, ?tl)) { - auto u_ = f(hd, u); - // FIXME: should use 'be' here, not 'ret'. But parametric - // tail calls currently don't work. - ret foldl[T,U](*tl, u_, f); - } - case (nil[T]) { - ret u; - } - } - - fail; // TODO: remove me when exhaustiveness checking works -} - -fn find[T,U](&list[T] ls, - (fn(&T) -> option.t[U]) f) -> option.t[U] { - alt(ls) { - case (cons[T](?hd, ?tl)) { - alt (f(hd)) { - case (none[U]) { - // FIXME: should use 'be' here, not 'ret'. But parametric tail - // calls currently don't work. - ret find[T,U](*tl, f); - } - case (some[U](?res)) { - ret some[U](res); - } - } - } - case (nil[T]) { - ret none[U]; - } - } - - fail; // TODO: remove me when exhaustiveness checking works -} - -fn length[T](&list[T] ls) -> uint { - fn count[T](&T t, &uint u) -> uint { - ret u + 1u; - } - ret foldl[T,uint](ls, 0u, bind count[T](_, _)); -} - -// Local Variables: -// mode: rust; -// fill-column: 78; -// indent-tabs-mode: nil -// c-basic-offset: 4 -// buffer-file-coding-system: utf-8-unix -// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; -// End: |