On Sat, Jan 1, 2011 at 8:39 PM, Henning Thielemann
<lemming@henning-thielemann.de> wrote:
On Sat, 1 Jan 2011, Jesse Schalken wrote:
> No definition for last works with infinite lists =).
Unless you make the result nullable, of course.
maybeLast :: [a] -> Maybe a
maybeLast [] = Nothing
maybeLast [x] = Just x
maybeLast (_:xs) = maybeLast xs
How would this work for infinite lists?
If your list is infinitely big, then reaching its end will take infinitely long. ;)
It will loop forever, just like `last [1...]` does.