Looking at the bracket
Parallel and Parallel Programming feature in Haskell :
bracket :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket before after during = do
a <- before
c <- during a `onException` after a
after a
return c
In the case of an exception, why is the function after
called only once? In other words, I am confused at explicit execution after a
twice in case of exception.
But, the code shows that after a
only, as I understand it, is only called once:
λ: >data MyException = MyException deriving Show
λ: >instance Exception MyException
λ: >let e = return MyException :: IO MyException
λ: >bracket e (const $ putStrLn "clean up!") return
clean up!
MyException
source
share