[Haskell-cafe] Haskell Propeganda

Robert Greayer robgreayer at yahoo.com
Wed Aug 27 17:01:46 EDT 2008


--- On Wed, 8/27/08, Dan Weston <westondan at imageworks.com> wrote:
> 
> Failure to handle a null pointer is just like using
> fromJust and results 
> in the same program termination (undefined).
> 
> Dan
> 

Well, not (IMHO) 'just like': 'fromJust Nothing' turns into a 'catchable' exception in the IO Monad, but a SEGFAULT certainly doesn't.

E.g.
> import Control.Exception as C
> import Data.Maybe
> main = do
>    (fromJust Nothing >>= ( \ s -> putStrLn s)) `C.catch` 
>        (\ _ -> putStrLn "ok")

prints 'ok', whereas:

> import Foreign.Ptr
> import Foreign.Storable
> import qualified Control.Exception as E
> main = poke nullPtr '\0' `E.catch` (\ _ -> putStrLn "ok")

just segfaults...





      


More information about the Haskell-Cafe mailing list