System.Timeout.timeout throws <<timeout>>
Summary
System.Timeout.timeout
throws a Timeout
exception to me, instead of returning Nothing
as documented.
Steps to reproduce
Load this file:
{-# LANGUAGE ScopedTypeVariables #-}
module Bug where
import Control.Exception
import System.Timeout
import Data.Maybe
data UserCodeResult a
= Timeout
| Exception String
| Success a
deriving Show
userCode :: IO a -> IO (UserCodeResult a)
userCode action = fmap (fromMaybe Timeout) $
timeout numMicroseconds $ do
result <- action
forced <- evaluate result
pure (Success forced)
`catch` \ (e :: SomeException) -> pure (Exception (displayException e))
where
numMicroseconds = 1 * 10^6
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
and then run userCode (return $ fib 1000)
.
Expected behavior
I want it to return Timeout
(because timeout
should return Nothing
). But instead it returns Exception "<<timeout>>"
, indicating a thrown exception.
Environment
Tested on GHC 8.6.1, on Mac OS 10.13.5.