[Haskell-cafe] Ultra-newbie Question

Henning Thielemann schlepptop at henning-thielemann.de
Mon Sep 20 05:05:27 EDT 2010


Luke Palmer schrieb:
> I think this is O(n) time, O(1) space (!).
> 
> lastk :: Int -> [a] -> [a]
> lastk k xs = last $ zipWith const (properTails xs) (drop k xs)
>     where properTails = tail . tails

If (drop k xs) is empty, this yields an error when calling 'last'. This
might be a bug or a feature.


More information about the Haskell-Cafe mailing list