On 8/1/06, Stephane Bortzmeyer <[EMAIL PROTECTED]> wrote:
How to do it in Haskell? How can I call functions like Prelude.head
while being sure my program won't stop, even if I call head on an
empty list (thus calling "error")?

Try looking at Control.Exception.  For example:

module Test where

import Control.Exception
import Prelude hiding (catch)

example =
  (do print (head (tail "a"))
      return "ok")
  `catch` (\e -> do putStrLn ("Caught exception: " ++ show e)
                    return "error")

produces:

*Test> z <- example
Caught exception: Prelude.head: empty list
*Test> z
"error"

This might be the beginning of what you want.

/g
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to