From: skaller <sk...@us...> - 2005-08-10 00:03:13
|
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.=20 Sounds good, but must not be implemented as you=20 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. > The second function is called split. =20 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). ****************** Consider generalise both functions so that the predicate=20 takes the whole of the remaining list as an argument, not just the next element. It is easy to write a predicate to only consider the first element, for example fun acc (h::_) -> ... isn't much harder to write than fun acc h -> but now we can pattern match to an arbitrary depth in the tail. Trivial example of tail match in fold_left_while: a list of characters finding the real content of the C++ code here / some // C++ code requires matching on //, which is two characters The problem is with "part" (your "split") it no longer makes sense to drop "the separator". --=20 John Skaller <skaller at users dot sourceforge dot net> |