Version française
Home     About     Download     Resources     Contact us    
Browse thread
Amb
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jonathan Bryant <jtbryant@v...>
Subject: Amb
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

(* val amb : (unit -> 'a) list -> 'a option *)

I know things are not added to the standard library lightly, but it  
seems that this one function doesn't really need it's own library and  
could be easily added somewhere.  It just seems that this would be a  
small but convenient addition.

--Jonathan Bryant