in the following example, the handler won't catch the exception because of lazy evaluation. therefore, it's a different story than with exceptions in ML, Python, whatever strict language. main = do xs <- return [ 1, 2, error "throw" ] `catch` \ any -> do putStrLn "caught" return [ 4, 5, 6 ] print xs -- -- Johannes Waldmann, Tel/Fax: (0341) 3076 6479 / 6480 -- ------ http://www.imn.htwk-leipzig.de/~waldmann/ ---------
On 2004-11-23, Johannes Waldmann <waldmann@imn.htwk-leipzig.de> wrote:
in the following example, the handler won't catch the exception because of lazy evaluation. therefore, it's a different story than with exceptions in ML, Python, whatever strict language.
main = do xs <- return [ 1, 2, error "throw" ] `catch` \ any -> do putStrLn "caught" return [ 4, 5, 6 ] print xs
That didn't quite compile as-is; I assume you ment: main = do xs <- return [ 1, 2, error "throw" ] `catch` \ any -> do putStrLn "caught" return [ 4, 5, 6 ] print xs When run, I get: Fail: throw In any case, in the more general case, I don't see a problem with that. I get an exception when I try to use something. That's fine. In an imperative program that solves the same problem the same way, you'd see the exception at the same point.
John Goerzen wrote:
main = do xs <- return [ 1, 2, error "throw" ] `catch` \ any -> do putStrLn "caught" return [ 4, 5, 6 ] print xs
When run, I get: Fail: throw
In any case, in the more general case, I don't see a problem with that. I get an exception when I try to use something. That's fine. In an imperative program that solves the same problem the same way, you'd see the exception at the same point.
No, in a traditional (strict) programming language the program would print caught [4,5,6] The exception "throw" would not appear in the output. -- Ben
participants (3)
-
Ben Rudiak-Gould -
Johannes Waldmann -
John Goerzen