From: Nicolas C. <war...@fr...> - 2005-08-10 17:20:31
|
> I propose the addition of two new functions into ExtList.List module. > I've found these to be useful in parsing and manipulating token lists. > I think these might be useful for other people as well. I'm not sure > if the naming is good, so feedback is welcome. There's already a > function called "split" in the List module, so I guess I need to come > up with some other name for it. The name stems from the functions > similarity to String.split. > val fold_left_while : > ('a -> 'b -> bool) -> ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a = <fun> I think too that having an exception is better than providing two functions. In general you want to stop recursion on a case that can't be treated by your "fold" , so you're already matching into your fold, with maybe an assert false in the case you already filtered it. It's better then to group both test+fold into a single function since I can't see good cases when you want to freely compose different folds and different stoppers. > The second function is called split. I've used it to split lists of > tokens into sublists (such as splitting argument lists by > COMMA-token). >> let split : ('a -> bool) -> 'a list -> 'a list list = <fun> That one might be useful in some cases. But it needs a new name ;) Nicolas |