[Haskell-cafe] no sparks?

Felipe Lessa felipe.lessa at gmail.com
Sun Dec 20 19:00:10 EST 2009


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.  Not that
I use it myself.

Link: http://hackage.haskell.org/package/unamb

--
Felipe.


More information about the Haskell-Cafe mailing list