3 ms·
Forgive my ignorance, but what about this method saves us from having to use continuations to unwind/rewind the stack, as Exceptions do?
by T-R 15y ago
Forgive my ignorance, but what about this method saves us from having to use continuations to unwind/rewind the stack, as Exceptions do?
- batterseapower 15y agoYou can implement "finally" as a higher order function in Haskell: finally :: Either err a -> IO () -> (a -> IO (Either err b)) -> IO (Either err b) finally (Left err) cleanup _k = cleanup >> return (Left err) finally (Right x) _cleanup k = k x You avoid having to unwind the stack because the user of finally has to manually convert into CPS in order to supply the higher order argument of type "a -> IO (Either err b)"