[Haskell-cafe] Re: defining last using foldr
Chaddaï Fouché
chaddai.fouche at gmail.com
Wed Aug 15 09:30:59 EDT 2007
2007/8/15, Aaron Denney <wnoise at ofb.net>:
> >
> > 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ï
More information about the Haskell-Cafe
mailing list