From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p8TFTEj0007246 for ; Thu, 29 Sep 2011 17:29:14 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtUBAICOhE6flYLKhWdsb2JhbABBqA8UAQEBCgsLGyWBUwEBBAEnEzMMBQsLDjhXBogNuFOHEwSTVoURjCs X-IronPort-AV: E=Sophos;i="4.68,461,1312149600"; d="scan'208";a="122168666" Received: from smtp.dico.unimi.it ([159.149.130.202]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 29 Sep 2011 17:29:07 +0200 Received: from ulik.disi.unige.it (ulik.disi.unige.it [130.251.61.165]) (authenticated bits=0) by smtp.dico.unimi.it (8.14.4/8.14.4) with ESMTP id p8TFT5Lq001815 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 29 Sep 2011 17:29:05 +0200 Date: Thu, 29 Sep 2011 17:29:00 +0200 (CEST) From: Walter Cazzola To: David Allsopp cc: "OCaml List (caml-list@inria.fr)" In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (LFD 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; FORMAT=flowed Content-ID: X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0 (smtp.dico.unimi.it [159.149.130.202]); Thu, 29 Sep 2011 17:29:05 +0200 (CEST) X-DSI-MailScanner-Information: Please contact the staff for more information X-DSI-MailScanner-ID: p8TFT5Lq001815 X-DSI-MailScanner: Found to be clean X-DSI-MailScanner-From: cazzola@dico.unimi.it Subject: RE: [Caml-list] still puzzled on generic types On Thu, 29 Sep 2011, David Allsopp wrote: > I think it's probably something to do with optional arguments not > behaving as you expect. uhm, would be interesting to see what is wrong on my use of the optional arguments. > But this is a bad use for optional arguments - you should instead use > a nested function to pass the accumulator values. This works fine: yes my first attempt was implemented with nested functions but ,,, > let enumerate l = > let rec enumerate acc n = function > h::ls -> enumerate ((n, h)::acc) (n + 1) ls > | [] -> List.rev acc > in > enumerate [] 0 l ... my nested function had a different name than the nextee function and I was passing l to it too. Could you explain me why your code works? in particular where does it take the list to enumerate? Silly question I know but it seems magic to me written in such a way > Concatenating lists is also expensive in terms of the left list so > your function is about as slow as possible! Much better when aiming > for tail recursion, accumulate a reversed list and then reverse it in > the basis case. Ok, thanks for the note, but efficiency issues are still far in my learning curve ;-) Walter --