[Haskell-cafe] an idea for modifiyng data/newtype syntax: use `::=` instead of `=`

Richard A. O'Keefe ok at cs.otago.ac.nz
Tue Aug 18 06:16:12 UTC 2015


On 9/08/2015, at 5:28 am, Hilco Wijbenga <hilco.wijbenga at gmail.com> wrote:
> I wholeheartedly agree with replacing the current "type" with "alias",

That would be to replace a precise time with a vague one.
All sorts of things can be aliased.  Especially when someone
writes code that I would like to use, but writes it with an
American accent, I would very much like to be able to do things
*like*
   alias Colour = Color
and I would like to do this for types, for modules, for constructors,
for plain functions, &c.  I am not saying that the same *form* of
declaration should be used in each case, but that declarations all
using the _word_ 'alias' should be available to make it quite plain
to the reader what is going on.  In particular, there is currently
no way to give an additional name to a constructor that lets you
*use* it as a constructor.  'alias' is far too potentially useful a
word to squander this way.

Consider ML:

   val thingy = 42

This says that 'thingy' is another name for the val(ue) 42.
It's an equality for values.

  type 'a sequence = 'a list

This says that for any type 't, 't sequence is another name
for the type 't list.  It's an equality for types.  Type is
the *perfect* word here, in ML.

Now Haskell does not the 'val' keyword (nor the 'fun' keyword)
and it doesn't need them.  But it *does* have two kinds of
type declaration, one of which *IS* a type equality
   type Sequence t = [t]
and *looks like it*, and one of which ISN'T a type equality.

If you want to argue about the grammar of 'data' declarations,
go right ahead.  I myself was a little confused by them at
the beginning, because the declare a new type and some
constructors, but do not declare 'data' in the sense that a
DATA statement in BASIC or Fortran or the DATA DIVISION in
COBOL does.  The word 'data' is so very far from conveying
the idea "introduce a new type" that it's not funny.

But to be confused by 'type' declarations?  That's, well, alien.
Especially as in the Haskell teaching material I'm familiar
with, people are introduced to 'type' declarations doing the
utterly familiar 'introduce a new name for an old type' thing
before they're introduced to 'data'.


> the current "type" is just flat out wrong: it does *not* create a
> type.

AND IT DOES NOT *CLAIM* TO CREATE A TYPE.
It claims to state a type EQUALITY, and it really does.

It's just like if you write

   answer = 42

This does NOT define a new constant.  It gives a new name for
an existing value.  Next thing someone will say that this ought
to be written

  value_alias answer = 42

or something.




More information about the Haskell-Cafe mailing list