@@ -11,49 +11,49 @@ tag list[T] {
11
11
}
12
12
13
13
fn foldl[ T , U ] ( & list[ T ] ls, & U u, fn ( & T t, & U u) -> U f) -> U {
14
- alt( ls) {
15
- case ( cons[ T ] ( ?hd, ?tl) ) {
16
- auto u_ = f ( hd, u) ;
17
- // FIXME: should use 'be' here, not 'ret'. But parametric
18
- // tail calls currently don't work.
19
- ret foldl[ T , U ] ( * tl, u_, f) ;
20
- }
21
- case ( nil[ T ] ) {
22
- ret u;
14
+ alt( ls) {
15
+ case ( cons[ T ] ( ?hd, ?tl) ) {
16
+ auto u_ = f ( hd, u) ;
17
+ // FIXME: should use 'be' here, not 'ret'. But parametric
18
+ // tail calls currently don't work.
19
+ ret foldl[ T , U ] ( * tl, u_, f) ;
20
+ }
21
+ case ( nil[ T ] ) {
22
+ ret u;
23
+ }
23
24
}
24
- }
25
25
26
- fail; // TODO: remove me when exhaustiveness checking works
26
+ fail; // TODO: remove me when exhaustiveness checking works
27
27
}
28
28
29
29
fn find[ T , U ] ( & list[ T ] ls,
30
30
( fn ( & T ) -> option:: t[ U ] ) f) -> option:: t[ U ] {
31
- alt ( ls) {
32
- case ( cons[ T ] ( ?hd, ?tl) ) {
33
- alt ( f ( hd) ) {
34
- case ( none[ U ] ) {
35
- // FIXME: should use 'be' here, not 'ret'. But parametric tail
36
- // calls currently don't work.
37
- ret find[ T , U ] ( * tl, f) ;
38
- }
39
- case ( some[ U ] ( ?res) ) {
40
- ret some[ U ] ( res) ;
31
+ alt ( ls) {
32
+ case ( cons[ T ] ( ?hd, ?tl) ) {
33
+ alt ( f ( hd) ) {
34
+ case ( none[ U ] ) {
35
+ // FIXME: should use 'be' here, not 'ret'. But parametric
36
+ // tail calls currently don't work.
37
+ ret find[ T , U ] ( * tl, f) ;
38
+ }
39
+ case ( some[ U ] ( ?res) ) {
40
+ ret some[ U ] ( res) ;
41
+ }
41
42
}
42
43
}
44
+ case ( nil[ T ] ) {
45
+ ret none[ U ] ;
46
+ }
43
47
}
44
- case ( nil[ T ] ) {
45
- ret none[ U ] ;
46
- }
47
- }
48
48
49
- fail; // TODO: remove me when exhaustiveness checking works
49
+ fail; // TODO: remove me when exhaustiveness checking works
50
50
}
51
51
52
52
fn length[ T ] ( & list[ T ] ls) -> uint {
53
- fn count[ T ] ( & T t, & uint u) -> uint {
54
- ret u + 1 u;
55
- }
56
- ret foldl[ T , uint] ( ls, 0 u, bind count[ T ] ( _, _) ) ;
53
+ fn count[ T ] ( & T t, & uint u) -> uint {
54
+ ret u + 1 u;
55
+ }
56
+ ret foldl[ T , uint] ( ls, 0 u, bind count[ T ] ( _, _) ) ;
57
57
}
58
58
59
59
fn cdr[ T ] ( & list[ T ] ls) -> list[ T ] {
0 commit comments