Hi how could one implement a function in concurrent haskell that either
returns 'a' successfully or due timeout 'b'?
timed :: Int → IO a → b → IO (Either a b)
timed max act def = do
Best Regards,
Cetin Sert
___
Haskell-Cafe mailing list
2009/5/30 Cetin Sert cetin.s...@gmail.com
Hi how could one implement a function in concurrent haskell that either
returns 'a' successfully or due timeout 'b'?
timed :: Int → IO a → b → IO (Either a b)
timed max act def = do
Something like (warning, untested code - no compiler atm).
timed
Thank you for your reply, I'd come up with the following:
timed :: Int → IO a → b → IO (Either b a)
timed max act def = do
r ← new
t ← forkIO $ do
a ← act
r ≔ Right a
s ← forkIO $ do
wait max
e ← em r
case e of
True → do
kill t
r ≔ Left def
On Sat, May 30, 2009 at 10:32 PM, Cetin Sert cetin.s...@gmail.com wrote:
Thank you for your reply, I'd come up with the following:
timed :: Int → IO a → b → IO (Either b a)
timed max act def = do
r ← new
t ← forkIO $ do
a ← act
r ≔ Right a
s ← forkIO $ do
wait max
The proper way is just to wrap System.Timeout, which does some rather
clever things with regards to exception semantics. The code for it is
a joy to read, by the way.
--S.
On May 30, 2009, at 5:36 PM, Sebastian Sylvan wrote:
On Sat, May 30, 2009 at 10:32 PM, Cetin Sert
-__- hehe why did I not let Hayoo or Hoogle help me there *sigh*
Thanks!!
2009/5/31 Sterling Clover s.clo...@gmail.com
The proper way is just to wrap System.Timeout, which does some rather
clever things with regards to exception semantics. The code for it is a joy
to read, by the way.
--S.