
Cale Gibbard wrote:
This is exactly why lists are so common. If people ask why lists are so common in lazy functional languages, they ought also to ask why loops are so common in imperative languages.
A loop is a sequence of actions. In FP, I don't typically have actions, rather I collect values, so I'd need several collections types, among them: sequences, and among them: classical left-biased lists. I admit that my typical Haskell program does use such lists all over the place, but mostly in monad comprehensions: do x <- ... ; guard ; let ... ; return ... and often it's a list only because there is no such syntactical convenience for, e. g. Sets. (I have to write lots of setToList/mkSet, which look plain ugly.) Even if I really want sequences, I rarely rely on the left-biased representation. (E. g. in the above example, there's no visible pattern matching on the 'cons'.) For reference, in Java, List<> is an interface, not a type (it has instances like LinkedList<> and ArrayList<>). And, there's nice syntactic sugar for looping over collections: Collection<E> c; for (E item : c) { ... } (it hides the pre-1.5 Iterator.hasNext/next stuff. I'd say this is an example of moving away from a left-biased representation, or at least freeing the programmer from having to think about it). Respectfully submitted, -- -- Johannes Waldmann -- Tel/Fax (0341) 3076 6479/80 -- ---- http://www.imn.htwk-leipzig.de/~waldmann/ -------