
15 Aug
2007
15 Aug
'07
9:30 a.m.
2007/8/15, Aaron Denney
The original "last" fail on empty list, it's far easier to obtain the same semantic with foldl than with foldr, in fact it isn't hard at all to make it polymorphic without hassle (contrary to the foldr case) _if_ you remember that there _is_ a value in Haskell wich belongs to every type.
Hah. True. That does simplify things considerably. Still, I'd call that an infelicity in last (and head, for that matter), and would rather have such errors handled at the call site than making the entire program fall over.
Control.Exception.catch (evaluate $ myLast []) print (in GHC it works) Still I don't see why foldl would make it harder to use Maybe than foldr (in fact it's easier). -- Jedaï