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)
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to