Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] "List.index" or "List.unique" functions?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-05-01 (01:59)
From: skaller <skaller@u...>
Subject: [Caml-list] List.rev
On Sat, 2004-05-01 at 05:08, Karl Zilles wrote:
> Rahul Siddharthan wrote:

> List.rev is not tail recursive, so you wouldn't want to use this 
> function on industrial size lists.

But it should be. Why isn't it???

let rev lst = let r = ref [] in
  let rec aux lst = match lst with
  | [] -> !r
  | h::t -> r:= h :: !r; aux t
in aux lst

BTW: documentation that says a function is 'tail recursive'
is misguided. That's an implementation detail of no
possible use to a user of the function. The user may
benefit from knowing the complexity of the function
in terms of speed and auxilliary storage required.

John Skaller,
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: