[Haskell-cafe] overloaded list literals?

Johannes Waldmann waldmann at imn.htwk-leipzig.de
Mon Sep 6 06:23:35 EDT 2010

I think left-biased (= singly linked) lists
are much overrated in Haskell coding (and teaching).

The language (syntax and Prelude) makes it just too easy to use them,
and old habits (from LISP) die hard.

Sure, lists serve a purpose: 
* they model (infinite, lazy) streams, used
  in the producer/transformer/consumer pattern
* they are an algebraic data type,
  so you can use them to teach recursion ((co-)induction);
but more often, lists are (mis-)used when actually
* you want some efficiently index-able and concat-able sequence type
* or you don't need the indexing, just membership, so you actually want Data.Set
  (disregarding strictness and unwanted Ord instances for the moment).
  It is an empirical law that in 90 percent of the cases where 
  a computer science student says "list" he means "set".
* you avoid/forget to tell your students about algebraic data types in general.

Hypothetically now ... 

We have overloaded numerical literals (Num.fromInteger)
and we can overload string literals (IsString.fromString),
so how about using list syntax ( [], : )
for anything list-like (e.g., Data.Sequence)?

Of course some "minor details" would need to be worked out,
like what methods should go in the hypothetical "class IsList"
(is is Foldable?) and what to do about pattern matching
(perhaps we don't need it?)

IIRC there was a time when list comprehension 
would actually mean monad comprehension 
(when there was no "do" notation)
but that's not what I'm getting at here. Or is it?
Do we have a "Haskell museum" of ideas from the past?

Best - J.W.

More information about the Haskell-Cafe mailing list