[Added timeOut' and timeOutMicro'. nad**20041021173147] { hunk ./ChasingBottoms/Header 48 -be able to apply a timeout. +be able to apply a timeout: + + [@> timeOut' 1 (reverse [1..5\]) >>= print@] @Just [5,4,3,2,1]@ + + [@> timeOut' 1 (reverse [1..\]) >>= print@] @Nothing@ + +Timeouts can also be applied to @IO@ computations: hunk ./ChasingBottoms/TimeOut.hs 15 +-- +-- Note that a computation is considered to have terminated when it +-- has reached weak head normal form (i.e. something distinct from +-- bottom). hunk ./ChasingBottoms/TimeOut.hs 20 -module ChasingBottoms.TimeOut( timeOut, timeOutMicro ) where +module ChasingBottoms.TimeOut + ( timeOut + , timeOut' + , timeOutMicro + , timeOutMicro' + ) where hunk ./ChasingBottoms/TimeOut.hs 56 + +-- | 'timeOut'' is a variant which can be used for pure +-- computations. The definition, +-- +-- @ +-- 'timeOut'' n = 'timeOut' n . Control.Exception.evaluate +-- @ +-- +-- ensures that @'timeOut'' 1 bottom@ usually returns 'Nothing'. +-- (@'timeOut' 1 (return bottom)@ usually returns @'Just' 'bottom'@.) +timeOut' :: Int -> a -> IO (Maybe a) +timeOut' n = timeOut n . evaluate + +-- | 'timeOutMicro'' is the equivalent variant of 'timeOutMicro': +-- +-- @ +-- 'timeOutMicro'' n = 'timeOutMicro' n . Control.Exception.evaluate +-- @ +timeOutMicro' :: Int -> a -> IO (Maybe a) +timeOutMicro' n = timeOutMicro n . evaluate }