[Haskell-cafe] Re: defining last using foldr

Aaron Denney wnoise at ofb.net
Tue Aug 14 18:47:54 EDT 2007

On 2007-08-14, Chaddaï Fouché <chaddai.fouche at gmail.com> wrote:
> 2007/8/14, Aaron Denney <wnoise at ofb.net>:
>> The problem with foldl is that you can't easily make it polymorphic
>> because of how the null case is handled.  foldl1 and foldr1 are trivial,
>> true.
> 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.

Aaron Denney

More information about the Haskell-Cafe mailing list