From: Christophe P. <chr...@gm...> - 2006-08-02 16:50:51
|
Greetings list, I recently tried to use String.nsplit on a rather large text file, which didn't go too well because the current implementation isn't tail recursive. Following is an implementation that I believe to be tail recursive and that should behave like the original version. Could you consider it for inclusion, if it doesn't break anything? let nsplit str sep = let try_split s = try Some (String.split s sep) with Invalid_string -> None in let rec loop str result = match try_split str with | Some (a, b) -> loop b (a :: result) | None -> if result = [] then [str] else List.rev result in loop str [] Comments and criticisms are of course most welcome. :-) Thanks a lot, Christophe |