From: Eric C. C. <ec...@cm...> - 2003-02-27 19:29:11
|
On Thu, Feb 27, 2003 at 07:51:43PM +0900, Nicolas Cannasse wrote: > > (* Generate the range of integers [a; a+1; ...; b] *) > > > > val range : int * int -> int list > > would prefer : > range : int -> int -> int list > since it's not causing any overhead due to the tuple allocation ( integer > are unboxed ) That's a reasonable argument. I like the suggestion of mathematical "interval notation" with range (1, 10), but don't feel strongly about it. > > (* Reverse assoc *) > > (* can also add rassq, mem_rassoc/rassq, remove_rassoc/rassq if needed *) > > > > val rassoc : 'b -> ('a * 'b) list -> 'a > > I reallly don't like theses. The usage of them are far from obvious My old Lisp habits are showing, I guess. > > (* String equivalents of Array.fold_left and Array.fold_right *) > > > > val string_fold_left : ('a -> char -> 'a) -> 'a -> string -> 'a > > val string_fold_right : (char -> 'a -> 'a) -> 'a -> string -> 'a I really think these are useful. For example: let checksum data = string_fold_left (fun n c -> (n + Char.code c) mod 256) 0 data let explode string = string_fold_right (fun c list -> c :: list) [] string > > (* Convert between strings and lists of chars. *) > > > > val explode : string -> char list > > val implode : char list -> string > > Theses four are interesting, but I don't realy see the need of using Strings > as char list. Could you tell me about it ? This is another Lisp influence. I find it easier to write "functional" string manipulation with these operators (versus the Buffer module, which is more efficient for large strings, but also more imperative and less flexible -- you can't go back and insert data at the beginning or middle). Thanks for all the comments. -- Eric C. Cooper e c c @ c m u . e d u |