16 fun foldr'' f (l,f2) = let fun itr [] = raise Fail "foldr''" |
16 fun foldr'' f (l,f2) = let fun itr [] = raise Fail "foldr''" |
17 | itr [a] = f2 a |
17 | itr [a] = f2 a |
18 | itr (a::l) = f(a, itr l) |
18 | itr (a::l) = f(a, itr l) |
19 in itr l end; |
19 in itr l end; |
20 fun foldr' f l = foldr'' f (l,Id); |
20 fun foldr' f l = foldr'' f (l,Id); |
21 fun map_cumulr f start xs = Library.foldr (fn (x,(ys,res))=>case f(x,res) of (y,res2) => |
21 fun map_cumulr f start xs = foldr (fn (x,(ys,res))=>case f(x,res) of (y,res2) => |
22 (y::ys,res2)) (xs,([],start)); |
22 (y::ys,res2)) ([],start) xs; |
23 |
23 |
24 |
24 |
25 fun first (x,_,_) = x; fun second (_,x,_) = x; fun third (_,_,x) = x; |
25 fun first (x,_,_) = x; fun second (_,x,_) = x; fun third (_,_,x) = x; |
26 fun upd_first f (x,y,z) = (f x, y, z); |
26 fun upd_first f (x,y,z) = (f x, y, z); |
27 fun upd_second f (x,y,z) = ( x, f y, z); |
27 fun upd_second f (x,y,z) = ( x, f y, z); |