[email protected]
[Top] [All Lists]

[Haskell-cafe] Re: no sparks?

Subject: [Haskell-cafe] Re: no sparks?
From: Benedikt Huber
Date: Mon, 21 Dec 2009 02:52:12 +0100
Daniel Fischer schrieb:
Am Sonntag 20 Dezember 2009 23:25:02 schrieb Jamie Morgenstern:
Hello;

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
And in this case (returning (Maybe Proof)), you are not happy with any
of the results, but with one of the proofs. So you would need something like
solve :: Ctx -> Prop -> Int -> IO (Maybe Proof)
solve ctx goal n = amb leftRight rightLeft
  where
    leftRight = m1 `mplus` m2
    rightLeft = m2 `mplus` m1
    m1 = (tryRight ctx goal n)
    m2 = (tryLeft ctx goal n)

I think the idea of directly supporting this kind of thing is quite interesting.
benedikt
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>