[Haskell-cafe] overloaded list literals?

Bulat Ziganshin bulat.ziganshin at gmail.com
Mon Sep 6 07:06:04 EDT 2010

Hello Johannes,

Monday, September 6, 2010, 2:23:35 PM, you wrote:

i had such idea several years ago and proposed to name class ListLike.
this class was finally implemented by John Goerzen and it does
everything we can w/o changing language

the main thing about literals is that they need to be recognized also
at left side of equations, so that

length (s:xs) = 1 + length xs
length []     = 0

will work for ByteStrings and arrays like it work for list. if it will
be implemented, then most programs manipulating on lists/strings, can
be converted to more efficient ones simply by replacing imports

Haskell 1.0 views may be the way to go, virtually converting other
containers to lists, back and forth. of course, only if these virtual
conversions will be optimized away by smart compiler

> 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.

> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list