I've noticed streams seem to act a lot like lists, except with constant time append. Of course, adding constant time append to lists isn't too complicated, and DList does exactly that.
Lets assume for the rest of the discussion that either lists have constant time append, or that we're simply not interested in it.
My thought is that Haskell lists should simply be implemented as streams. For this not to be the case, I assume that the following would need to hold:
- There are cases where lists are better than streams AND
- There are cases where streams are better than lists.
My question is: what are examples of the two above cases?
Note: For the purpose of this question, please ignore easily fixable omissions in the particular implementations I've discussed. I'm looking more for core structural differences here.
Additional info:
I guess part of what I'm getting at here is say if we write [1..1000000], does a Haskell compiler (say GHC) do:
- Make a list OR
- Make an object with two ints: 1 and 1000000 which fully describes the list.
If it's case (1), why do this, as creating intermediate lists seems to be an unnecessary performance penalty?
Or if it's case (2), then why do we need streams?