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

Alexey Muranov alexey.muranov at gmail.com
Mon Aug 17 21:16:51 UTC 2015


Funnily, i've just noticed that this notation with `::=` to define data 
types is used in [Why Functional Programming Matters by John 
Hughes](http://www.cse.chalmers.se/~rjmh/Papers/whyfp.html).

Just a remark.

Alexey.

On Saturday, August 8, 2015 at 1:09:24 PM UTC+2, Alexey Muranov wrote:
>
> Hello, 
>
> i would like to suggest an idea for modifying the basic data/newtype 
> syntax in Haskell: replace the equality sign `=` with `::=`. 
>
> When i started learning Haskell, the most confusing part of the syntax for 
> me was the equality sign in `data` definition.  I could not even guess what 
> the `data` definition meant without reading a chapter or two about types in 
> Haskell, and i think it was partially due to the equality sign.  I still 
> find this notation inconsistent with other uses of the equality sign in 
> Haskell and in general. 
>
> For example, in 
>
>     type Name = String 
>     data Date = Date Int Int Int 
>     data Anniversary = Birthday Name Date | Wedding Name Name Date 
>
> the second line is particularly disorienting IMO because on two sides of 
> the equality, `Date` denotes different things. 
>
> As far as i understand, in all contexts except those of `data` and 
> `newtype` definitions, the equality sign in Haskell denotes the actual 
> equality for all purposes: if a line 
>
>     foo x y = bar y x 
>
> is present in a program, `foo a b` and `bar b a` can be used more or less 
> interchangeably elsewhere in the program.  Similarly, if the line 
>
>     type Name = String 
>
> is present, `Name` can be used as `String`.  Clearly, the equality in 
>
>     data Date = Date Int Int Int 
>
> does not have such property. 
>
> I think that if `::=` was used instead of `=` in `data` and `newtype` 
> definitions, this would suggest  to a newcomer that the syntax of the two 
> sides might be different, and would helpfully remind of the Backus–Naur 
> Form for syntax rules.  I think that a newcomer to Haskell, like myself, 
> would have had a better chance of guessing the meaning of 
>
>     type Name = String 
>     data Date ::= Date Int Int Int 
>     data Anniversary ::= Birthday Name Date | Wedding Name Name Date 
>
> IMO this would make the program easier to read in general and the 
> difference between `type` and `newtype` more clear.  Maybe the can even 
> make the use of keywords redundant, by allowing to write simply 
>
>     Name = String 
>     Date ::= Date Int Int Int 
>     Anniversary ::= Birthday Name Date | Wedding Name Name Date 
>
> What do you think? 
>
> Alexey. 
> _______________________________________________ 
> Haskell-Cafe mailing list 
> Haskell-Cafe at haskell.org 
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe 
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150817/5cc3ac92/attachment.html>


More information about the Haskell-Cafe mailing list