Haskell ~ Does last iterate the entire list?

haskell, list

Solution

Yes, Haskell's list are singly linked and thus `last` needs to walk through the entire list, making its runtime `O(n)`.

Problem

Simple question for Haskellites: Does Haskell iterate an entire sequence to obtain the last value? Specifically, are a different number of instructions executed for these two expressions? ``` Prelude> last "asdf" 'f' Prelude> last "qwerty" 'y' ```

Original source