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: Brian Hurt <bhurt@s...>
Subject: Re: [Caml-list] Amb


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