Ny particular reason for the use of lists over queues in functional programming languages

data structuresfunctional programminghaskellscheme

Most functional programming languages such as Scheme and Haskell use lists as their main data structure. Queues are identical to lists, except for the fact appending to the end – not to the begin – has constant time. Every algorithm that is written elegantly using lists with head and tail can be written elegantly using queues with init and last.

Considering appending to the end is more common than the opposite, I'd guess queues are more natural than lists. Is there any reason lists have always been preferred?

Best Answer

Queues don't functionally compose, and are difficult to implement in a well-performing way without making them mutable.

The very nature of a queue suggests that you put things into it and take things out of it, which is at odds with the immutable nature of functional languages. Oh, sure, you can do the same thing with lists, but generally what you are really doing is composing a new list, not adding to one, and a list doesn't have the special requirement of forcing you to put items into one end and take them out of the other, like a queue does.

All that said, have a look at Okasaki's paper on Purely Functional Data Structures, which does outline a strategy for creating a queue with adequate performance in a functional way.