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

Lars Hupel lars at hupel.info
Sat Aug 8 14:29:22 UTC 2015

Hi Alexey,

> 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

there is already an alternative syntax for declaring datatypes:

data Date where
  Date :: Int -> Int -> Int -> Date

data Anniversary where
  Birthday :: Name -> Date -> Anniversary
  Wedding :: Name -> Name -> Date -> Anniversary

This is called "GADT syntax" and can be enabled with -XGADTSyntax in GHC.*


* The underlying machinery also extends the fragment of admissible
datatype declarations beyond what is possible with the standard syntax.

More information about the Haskell-Cafe mailing list