---------------------
*Network.Port.Scan> timed 500 (wait 50000 >> return 0) 'x'
Left 'x'
*Network.Port.Scan> timed 500000 (wait 50000 >> return 0) 'x'
Right 0
---------------------
before reading your reply:
timed timeout act fallback = do
res <- newEmptyMVar
tid <- forkIO $ act >>= writeMVar res
threadDelay timeout
stillRunning <- isEmptyMVar res
if stillRunning then killThread tid >> return fallback else takeMVar res
---------------------
*Network.Port.Scan> timed2 500 (wait 50000 >> return 0) 'x'
<interactive>:1:33:
No instance for (Num Char)
arising from the literal `0' at <interactive>:1:33
Possible fix: add an instance declaration for (Num Char)
In the first argument of `return', namely `0'
In the second argument of `(>>)', namely `return 0'
In the second argument of `timed2', namely
`(wait 50000 >> return 0)'