[Haskell-cafe] Definition of List type?

Ben Millwood haskell at benmachine.co.uk
Fri Jul 30 15:03:01 EDT 2010


On Fri, Jul 30, 2010 at 7:50 PM, Gregory Crosswhite
<gcross at phys.washington.edu> wrote:
>
> The reason why this definition never actually appears is because it defines the constructors using operators rather than names, which is not allowed in vanilla Haskell.  (There is an extension, TypeOperators, however, that does allow this.)
>

 Nope: see Data.Complex.Complex; only infix *type* constructors are
nonstandard. The thing about lists that makes them impossible to
define in normal Haskell is the [a] syntax, which is some kind of
"outfix" type constructor, which no amount of currently available
extensions will allow. In addition, the constructor [] for the empty
list isn't a normal constructor, syntactically, because it doesn't
start with an uppercase character or a colon.

Basically, lists are so ubiquitous in Haskell that they have their own
special syntax, which cannot be defined like any other data type. It
is simple, as others have said, to define a new data type that works
identically to lists.


More information about the Haskell-Cafe mailing list