caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Amb
@ 2007-02-09 21:31 Jonathan Bryant
  2007-02-09 21:55 ` [Caml-list] Amb Brian Hurt
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Bryant @ 2007-02-09 21:31 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-02-10  1:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-09 21:31 Amb Jonathan Bryant
2007-02-09 21:55 ` [Caml-list] Amb Brian Hurt
2007-02-09 22:12   ` Andrej Bauer
2007-02-09 22:42     ` Tom
2007-02-10  0:03       ` Jon Harrop
2007-02-10  0:01   ` Jon Harrop
2007-02-10  1:12     ` Brian Hurt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).