
3 Aug
2004
3 Aug
'04
2:08 p.m.
Exceptions should only really be used for unpredictcable events, I find that the defintion of functions like head is lacking rigor... I would prefer to see:
head :: [a] -> Maybe a head (a0:_) = Just a0 head _ = Nothing
In principle, yes, but in practice, that would be silly. You use "head" just when you know for sure that the list is non-empty; if it is not, it's a "program error" for head, and an "impossible error" for the caller. Consider: f (head xs) -- old style vs f (case head xs of Some x -> x; None -> error "whoops") -- Schupke style It should be clear that this function would never be used - if head had this signature, programmers would just write f (case xs of (x:_) -> x; [] -> error "whoops") -- direct style --KW 8-)