I like to write programs so functions cannot fail...
so head should really be:

        maybeHead :: [a] -> Maybe a
        maybeHead (a:_) = Just a
        maybeHead _ = Nothing

etc...

The the calling function can do something like:

        case maybeHead x of
                Just y -> <expr y>
                Nothing -> fail "failed in..."

This way you can pass the failure back up to somewhere where
its meaningful.

In my opinion you should either be encoding failure in the
return type, or using exceptions... anything else is just
bad coding.

Finally use guards (that can be conditionally compiled out)
before functions that might fail:

        if null x then fail "sesible error message" else ...

Keean.
_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to