ChasingBottoms-1.2.4: For testing partial and infinite values.Source codeContentsIndex
Portabilitynon-portable (preemptive scheduling)

When dealing with "hard bottoms", i.e. non-terminating computations that do not result in exceptions, the following functions may be handy.

Note that a computation is considered to have terminated when it has reached weak head normal form (i.e. something distinct from bottom).

data Result a
= Value a
| NonTermination
| Exception Exception
timeOut :: Int -> IO a -> IO (Result a)
timeOut' :: Int -> a -> IO (Result a)
timeOutMicro :: Int -> IO a -> IO (Result a)
timeOutMicro' :: Int -> a -> IO (Result a)
data Result a Source
Value a
Exception Exception
show/hide Instances
timeOut :: Int -> IO a -> IO (Result a)Source

timeOut n c runs c for at most n seconds (modulo scheduling issues).

  • If the computation terminates before that, then Value v is returned, where v is the resulting value. Note that this value may be equal to bottom, e.g. if c = return Test.ChasingBottoms.IsBottom.bottom.
  • If the computation does not terminate, then NonTermination is returned.
  • If the computation raises an exception, then Exception e is returned, where e is the exception.
timeOut' :: Int -> a -> IO (Result a)Source

timeOut' is a variant which can be used for pure computations. The definition,

   timeOut' n = timeOut n . evaluate

ensures that timeOut' 1 Test.ChasingBottoms.IsBottom.bottom usually returns Exception <something>. (timeOut 1 (return Test.ChasingBottoms.IsBottom.bottom) usually returns Value Test.ChasingBottoms.IsBottom.bottom; in other words, the computation reaches whnf almost immediately, defeating the purpose of the time-out.)

timeOutMicro :: Int -> IO a -> IO (Result a)Source
timeOutMicro takes a delay in microseconds. Note that the resolution is not necessarily very high (the last time I checked it was 0.02 seconds when using the standard runtime system settings for GHC).
timeOutMicro' :: Int -> a -> IO (Result a)Source

timeOutMicro' is the equivalent variant of timeOutMicro:

  timeOutMicro' n = timeOutMicro n . evaluate
Produced by Haddock version 2.4.2