[Haskell-cafe] defining last using foldr
Chaddaï Fouché
chaddai.fouche at gmail.com
Fri Aug 17 19:23:38 EDT 2007
For a really good article to see how foldr is in fact very powerful
and how you can make it do some funny tricks, see the Monad.Reader 6th
issue :
http://www.haskell.org/sitewiki/images/1/14/TMR-Issue6.pdf
I'll point out that you can write a lazy dropWhile with foldr in the
style of the first example of the article just by using a
non-refutable pattern in the combine function :
dWLazy p = snd . foldr (\a ~(x, y) -> if p a then (a : x, y) else (a :
x, a : x)) ([], [])
--
Jedaï
More information about the Haskell-Cafe
mailing list