[Haskell-cafe] getting last char of String

Jesse Schalken jesseschalken at gmail.com
Sat Jan 1 12:11:24 CET 2011


On Sat, Jan 1, 2011 at 10:06 PM, Jesse Schalken <jesseschalken at gmail.com>wrote:

>
>
> On Sat, Jan 1, 2011 at 8:39 PM, Henning Thielemann <
> lemming at henning-thielemann.de> wrote:
>
>>
>> On Sat, 1 Jan 2011, Jesse Schalken wrote:
>>
>>  On Sat, Jan 1, 2011 at 8:54 AM, Felipe Almeida Lessa <
>>> felipe.lessa at gmail.com> 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.
>
>
Oh, sorry. My participation in this thread can be safely ignored. I read "No
definition of last works for infinite lists" as "No definition of last works
for empty lists", sorry.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110101/556a7b28/attachment.htm>


More information about the Haskell-Cafe mailing list