23 Jun
2004
23 Jun
'04
7:56 p.m.
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.