From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 32566BC69 for ; Sat, 10 Feb 2007 02:01:15 +0100 (CET) Received: from bsd4.nyct.net (mail-out4.nyct.net [216.139.141.4]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1A11Dht020906 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 10 Feb 2007 02:01:14 +0100 Received: from [216.139.138.9] ([216.139.138.9]) by bsd4.nyct.net (8.13.4/8.13.4) with ESMTP id l1A1164o040822; Fri, 9 Feb 2007 20:01:09 -0500 (EST) (envelope-from bhurt@spnz.org) Date: Fri, 9 Feb 2007 20:12:45 -0500 (EST) From: Brian Hurt X-X-Sender: bhurt@localhost To: Jon Harrop Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Amb In-Reply-To: <200702100001.55094.jon@ffconsultancy.com> Message-ID: References: <1197BD5D-1373-4876-8DC1-FED84797E4A6@valdosta.edu> <45CCEDCC.1090200@janestcapital.com> <200702100001.55094.jon@ffconsultancy.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at discorde with ID 45CD1959.005 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; recursion:01 recursive:01 recursive:01 amb:98 2007,:98 amb:98 wrote:01 wrote:01 rec:01 caml-list:01 tail:01 match:02 slightly:03 ops:03 let:03 On Sat, 10 Feb 2007, Jon Harrop wrote: > On Friday 09 February 2007 21:55, Brian Hurt wrote: >> let rec amb = function >> >> | [] -> None >> | h :: t -> >> >> let r = >> try >> Some(h ()) >> with >> >> | _ -> None >> >> in >> match r with >> >> | None -> amb t >> | Some(_) as e -> e >> >> As a slightly better implementation. > > I think you're trying to box the returned value in order to evade non-tail > recursion but the OPs function was actually already tail recursive because > the recursive call to "amb" occurs outside the try..with. He was doing the boxing on the return as well. And note, in the above code I only box once. Brian