[Haskell-cafe] Re: no sparks?

Benedikt Huber benjovi at gmx.net
Sun Dec 20 19:43:30 EST 2009

Felipe Lessa schrieb:
> On Mon, Dec 21, 2009 at 12:39:06AM +0100, Daniel Fischer wrote:
>> Am Sonntag 20 Dezember 2009 23:25:02 schrieb Jamie Morgenstern:
>>> Also, I was wondering if something akin to a "parallel or" exists. By this,
>>> I mean I am looking for a function which, given x : a , y : a, returns
>>> either, whichever computation returns first.
>> This wouldn't be easy to reconcile with referential transparency.
>> You can do that in IO, roughly
>> m <- newEmptyMVar
>> t1 <- forkIO $ method1 >>= putMVar m
>> t2 <- forkIO $ method2 >>= putMVar m
>> rs <- takeMVar m
>> killThread t1
>> killThread t2
>> return rs
>> But in pure code, I think not.
> There's 'unamb' in Hackage, however I think you should carefully
> understand its implementation details before using it.  
Hello Jamie,
you might want to have a look at the implementation of `race` in the 
Conal's 'unamb' package:


As your left and right branch do not neccessarily have the same result, 
you have to stay in the IO monad.
The function provided by that package is:

 > amb :: a -> a -> IO a

> Not that I use it myself.
Neither do I, btw.


More information about the Haskell-Cafe mailing list