From: Richard J. <ri...@an...> - 2005-08-10 16:34:40
|
On the subject of new list functions, how about: let rec list_map_pairs f = function | [] | [_] -> invalid_arg "list_map_pairs" | [x; y] -> [f x y] | x :: (y :: _ as xs) -> f x y :: list_map_pairs f xs We use this sort of pattern to disaggregate data which has been collected using an incrementing counter - something like this: # let xs = [ 0; 1; 4; 5; 5; 5; 8; 9; 9; 10 ];; val xs : int list = [0; 1; 4; 5; 5; 5; 8; 9; 9; 10] # list_map_pairs (fun a b -> b - a) xs;; - : int list = [1; 3; 1; 0; 0; 3; 1; 0; 1] 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 |