From: Richard J. <ri...@an...> - 2005-02-17 23:47:28
|
A common pattern, one which I use frequently anyway, is to write a pair of functions like this: let add_elem, get_elems = let elems = ref [] in let add_elem r = elems := r :: !elems in let get_elems () = List.rev !elems in add_elem, get_elems;; followed by imperative-style code to add elements to the list, and finally return the list with get_elems (). Could ExtList contain such a "list building" function? ie. It would be a function which returned a pair of functions as above, something like: let add, get = ExtList.List.build () where build would be defined as: let build () = let xs = ref [] in let add x = xs := x :: !xs in let get () = List.rev !xs in add, get Thoughts? Rich. -- Richard Jones, CTO Merjis Ltd. Merjis - web marketing and technology - http://merjis.com Team Notepad - intranets and extranets for business - http://team-notepad.com |