From: Alan P. <ap...@re...> - 2005-08-14 17:00:23
|
In article <200...@fu...>, Richard Jones wrote: > On Wed, Aug 10, 2005 at 06:34:19PM +0000, Alan Post wrote: >> In article <200...@fu...>, Richard W. M. Jones wrote: >> > >> > Well OK, but we don't even have a function to do the >> > int list -> (int * int) list transformation. >> >> A fold using a ref would work, yes? > > Something like that might, but the whole point of HOFs is to avoid > having to write ugly hacks all the time :-) OK, here's a tail-recursive function using a fold without a ref: let take_pairs = let f (i,l) j = (j, (i,j)::l) in function | [] -> [] | h::tl -> List.rev (snd (List.fold_left f (h, []) tl)) |