Control.OldException . , . maybeIO
perhaps ∷ forall a. IO a → IO (Maybe a)
perhaps task = do
result ← (try ∷ IO a → IO (Either IOException a)) task
return $ either (const Nothing) Just result
You must specify an explicit forallone to bring the type variable ainto scope, and -XExplicitForAlluse the GHC compiler flag explicitly forall. You cannot give a trytype in clear text without receiving the error "You cannot specify a type signature for the imported value." If you try type declaration elsewhere, for example. by the result try task, the GHC cannot figure it out. So yes, it's a little awkward for us, strong lawyers, but it gets better.
source
share