From: Brian H. <bh...@sp...> - 2005-08-10 00:45:19
|
On Wed, 10 Aug 2005, skaller wrote: > On Wed, 2005-08-10 at 00:28 +0900, Janne Hellsten wrote: > >> First one is called fold_left_while. It works the same way as >> fold_left except that it breaks the loop as soon as a "while >> predicate" returns false. > > Sounds good, but must not be implemented as you > have written it. The real implementation must use an > inner exception to stop recursing, we do not want > to uselessly scan the rest of the list after the > termination condition is found. I don't think we need an exception to do this. Wouldn't this do: let fold_left_while f p init lst = let rec loop accu = function | h :: t -> if p h then loop (f accu h) t else accu | [] -> accu in loop init lst ;; >> The second function is called split. > > List.split already exists, it splits a list of pairs > into two lists, perhaps call it "part"? (short for > partition .. but that isn't quite accurate). List.partition already exists as well. Brian |