File: Exception.hs

package info (click to toggle)
haskell-foundation 0.0.30-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 932 kB
  • sloc: haskell: 9,124; ansic: 570; makefile: 7
file content (15 lines) | stat: -rw-r--r-- 452 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module Foundation.Exception
    ( finally
    , try
    , SomeException
    ) where

import Basement.Imports
import Control.Exception (SomeException)
import Foundation.Monad.Exception

finally :: MonadBracket m => m a -> m b -> m a
finally f g = generalBracket (return ()) (\() a -> g >> return a) (\() _ -> g) (const f)

try :: (MonadCatch m, Exception e) => m a -> m (Either e a)
try a = catch (a >>= \ v -> return (Right v)) (\e -> return (Left e))