Check out nomeata's blog post "On taking the last n elements of a list". There's the obvious
takeLast n = (reverse . take n . reverse)
but all that reversing is a lot of work. The temptation is to think imperative and haul out the heavy artillery... but then he realized how it could be done efficiently and idiomatically. I won't put a spoiler here; read the original.
random notes and thoughts, mostly about Haskell these days, of a rather past middle-aged programmer
Subscribe to:
Post Comments (Atom)
Riddler Classic, May 23, 2020—Holy Mackerel!
Another one using Peter Norvig's word list . It turns out that the word "mackerel" has a curious property: there is exactly ...
-
So, how about that tree? It's tempting to do something like van Laarhoven describes, though I'd be tempted to put maxima on the left...
-
"Why I'm Interested in Haskell" --not the writing of a fanboy, but of someone who I think fairly assessed the state of the pro...
-
Another one using Peter Norvig's word list . It turns out that the word "mackerel" has a curious property: there is exactly ...
No comments:
Post a Comment