[Haskell-cafe] Ultra-newbie Question

Nils Schweinsberg ml at n-sch.de
Sat Sep 18 08:29:25 EDT 2010


Am 18.09.2010 09:51, schrieb Christopher Tauss:
> I am trying to write a function that takes a list and returns the last n
> elements.

last_n n = fst . foldr step ([], n)
   where
     step _ (xs, 0) = (xs, 0)
     step x (xs, n) = (x:xs, n-1)


More information about the Haskell-Cafe mailing list