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=AWL 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 085E1BC69 for ; Fri, 9 Feb 2007 22:55:30 +0100 (CET) Received: from smtp.janestcapital.com (www.janestcapital.com [66.155.124.107]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l19LtSJo025128 for ; Fri, 9 Feb 2007 22:55:29 +0100 Received: from [192.168.250.117] [209.213.205.130] by janestcapital.com with ESMTP (SMTPD-9.10) id ADCC0158; Fri, 09 Feb 2007 16:55:24 -0500 Message-ID: <45CCEDCC.1090200@janestcapital.com> Date: Fri, 09 Feb 2007 16:55:24 -0500 From: Brian Hurt User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jonathan Bryant Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Amb References: <1197BD5D-1373-4876-8DC1-FED84797E4A6@valdosta.edu> In-Reply-To: <1197BD5D-1373-4876-8DC1-FED84797E4A6@valdosta.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 45CCEDD0.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; node:01 ocaml:01 amb:98 amb:98 16.:98 chap:98 wrote:01 rec:01 rec:01 ccs:01 exception:01 caml-list:01 neu:02 implemented:02 match:02 Jonathan Bryant wrote: > All, > > I'm having to learn Scheme for a class, and I ran across a simple but > really useful predicate: amb. More info on this can be found here: > http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z- > H-16.html#node_chap_14 > > Since OCaml doesn't seem to have this, I implemented it: > > exception Amb > let rec amb l = match l with > | [] -> raise Amb > | h::t -> try h () with Amb -> amb t > > let amb l = try Some (amb l) with Amb -> None > You might try: 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. Brian