[Haskell-cafe] defining last using foldr
Chaddaï Fouché
chaddai.fouche at gmail.com
Tue Aug 14 17:16:01 EDT 2007
2007/8/14, Alexteslin <alexteslin at yahoo.co.uk>:
> Well, i have tried cons (:) operator but when it passed to foldr doesn't work
> because cons operator operates first character and then the list but the
> foldr argument takes a function (a->a->a). Maybe i am missing the point
> here?
>
What Aaron was saying was that in this list :
1 : 2 : 3 : 4 : []
A fold replaced the cons (:) by another function (and [] by another constant).
Your problem isn't so easy to do with a foldr, a foldl would be easier
and a foldr1 or foldl1 even better. Are you sure you can't use one of
those other folds ?
--
Jedaï
More information about the Haskell-Cafe
mailing list