src/Pure/library.ML
changeset 20510 5e844572939d
parent 20443 84a624a8f773
child 20854 f9cf9e62d11c
equal deleted inserted replaced
20509:073a5ed7dd71 20510:5e844572939d
   542   in  itr l  end;
   542   in  itr l  end;
   543 
   543 
   544 (*  (op @) [x1, ..., xn]  ===>   x1 @ (x2 ... @ (x[n-1] @ xn))
   544 (*  (op @) [x1, ..., xn]  ===>   x1 @ (x2 ... @ (x[n-1] @ xn))
   545     for n > 0, operators that associate to the right (not tail recursive)*)
   545     for n > 0, operators that associate to the right (not tail recursive)*)
   546 fun foldr1 f [] = raise Empty
   546 fun foldr1 f [] = raise Empty
   547   | foldr1 f l = 
   547   | foldr1 f l =
   548       let fun itr [x] = x
   548       let fun itr [x] = x
   549 	    | itr (x::l) = f(x, itr l)
   549             | itr (x::l) = f(x, itr l)
   550       in  itr l  end;
   550       in  itr l  end;
   551 
   551 
   552 fun fold_index f =
   552 fun fold_index f =
   553   let
   553   let
   554     fun fold_aux _ [] y = y
   554     fun fold_aux _ [] y = y
   566   in fold_aux end;
   566   in fold_aux end;
   567 
   567 
   568 
   568 
   569 (* basic list functions *)
   569 (* basic list functions *)
   570 
   570 
   571 fun eq_list eq (xs, ys) =
   571 fun eq_list eq (list1, list2) =
   572   let
   572   let
   573     fun eq' [] [] = true
   573     fun eq_lst (x :: xs, y :: ys) = eq (x, y) andalso eq_lst (xs, ys)
   574       | eq' (x :: xs) (y :: ys) = eq (x, y) andalso eq' xs ys
   574       | eq_lst _ = true;
   575   in length xs = length ys andalso eq' xs ys end;
   575   in length list1 = length list2 andalso eq_lst (list1, list2) end;
   576 
   576 
   577 fun maps f [] = []
   577 fun maps f [] = []
   578   | maps f (x :: xs) = f x @ maps f xs;
   578   | maps f (x :: xs) = f x @ maps f xs;
   579 
   579 
   580 fun chop 0 xs = ([], xs)
   580 fun chop 0 xs = ([], xs)