[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SYNTAX ONLY but you should READ!



Date: 30 May 91 17:15
From: haskell-request@cs.glasgow.ac.uk
Sender: Maria Mercedes Gutierrez de Guzman <guzman-maria@cs.yale.edu>
To: haskell@cs.yale.edu
Subject: SYNTAX ONLY but you should READ!

Original-Via: uk.ac.nsf; Thu, 30 May 91 16:37:40 BST
Original-Sender: guzman-maria@cs.yale.edu


This is a compilation of all the proposed changes in the Haskell syntax from
the Haskell Report 1.0.  Please take a close look at it.

Most of the changes have been agreed on, but there are still some that
have not reached consensus:

- Allow floats to have a + in the exponent
- Renaming and modules (original names)
- Elimination of guards in lamda abstraction 
- Sections
- Auxiliary bindings in list comprehensions

If you would like a copy of the dvi file containing the full syntax
and list of syntax changes, do anonymous ftp to nebula.cs.yale.edu and
pull the file pub/haskell/new-syntax.dvi.Z

Enjoy!

Maria M.


NOTE: Words enclosed by @ are reserved words.  

Lexical Changes
~~~~~~~~~~~~~~~

Changes in the lexical syntax follow:


  *  [Pages~7 and 114:] A nested comment begins with @{-@ and ends
with @-}@; it can be between any two lexemes.  All characters are
ignored within the nested comment.  Nested comments may be nested to
any depth: any occurrence of @{-@ within the nested comment starts a
new nested comment, terminated by @-}@.  Within a block comment, each
@{-@ is matched by a corresponding occurrence of @-}@.''

ncomment	-> @{-@ ANYseq \{ncomment ANYseq\} @-}@
ANYseq		-> \{ANY\}_{\{ANY\} ( @{-@ | @-}@ ) \{ANY\}}
ANY		-> any | newline | vertab | formfeed


  *  [Pages~7 and 115:] To cope with parsing @\~x -> x@ and such,
appearance of @\@, @~@ and @-@ has been restricted to be a "presymbol".

avarop		-> ( ( symbol | presymbol ) \{symbol | @:@\} )_{\{reservedop\}}
presymbol	-> @~@ | @-@
symbol		-> @!@ | @#@ | @$@ | @%@ | @\@ | @&@ | @*@ | @+@ | @.@ |
                   @/@ | @<@ | @=@ | @>@ | @?@ | @@ | @^@ | @|@
reservedop	-> @..@ | @::@ | @=>@ | @=@ | @@ | @\@ | @|@ | @~@ | @<-@ |
                   @->@


  *  [Pages~7 and 115:] The keywords @let@ and @in@ has been added to
the list of "reservedid". 

reservedid -> @case@ | @class@ | @data@ | @default@ | @deriving@ |
              @else@ | @hiding@ | @if@ | @import@ | @infix@ | @infixl@ | 
              @infixr@ | @instance@ | @interface@ | @module@ | @of@ |
              @renaming@ | @then@ | @to@ | @type@ | @where@ | @let@ | @in@


  *  [Pages~8 and 115:] The exponent in floating point literals can
be either upper or lower case.  Also, floating points can have an
explicit positive exponent.

float		-> integer@.@integer[\{@e@ | @E@\}[@-@|@+@]integer]




Context-Free Syntax Changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following are the changes to the syntax:


  *  Empty declarations have been added to the syntax to aid automatic
program generation.

  *  [Pages~10 and 119:] LET expressions have been added.

  *  [Pages~10,11 and 119:] Guards have been eliminated from lambda
expressions. 

  *  [Pages~10, 16, 32, 118 and 119:] Insure that precedences and
parenthesization are handled uniformly in expressions, patterns, and
lefthand sides.

Operator precedence and associativity has been added to the syntax of
lhs as follows:

lhs	->  apat
	|   funlhs
funlhs	->  afunlhs
	|   pat^{i+1}_1 varop^{(n,i)} pat^{i+1}_2  & (0<=i<=9)
	|   lpat^i varop^{(l,i)} pat^{i+1}	   & (0<=i<=9)
	|   pat^{i+1} varop^{(r,i)} rpat^i	   & (0<=i<=9)
afunlhs ->  var apat
	|   @(@ funlhs @)@ apat
	|   afunlhs apat


Expression precedence has been dissambiguated and @let@ has been added
to the syntax:

exp	->  @\@ apat_1 ... apat_n @->@ exp 	& (\tr{lambda abstraction}, n>=1)
	|   @let@ @{@ decls @}@ @in@ exp	& {\tr{let expression}}
	|   @if@ exp @then@ exp @else@ exp	& (\tr{conditional})
	|   @case@ exp @of@ @{@ alts @}@	& (\tr{case expression})
	|   exp^0 [@::@ [context @=>@] atype]	& (\tr{expression type signature})
exp^i	->  exp^{i+1} [op^{(n,i)} exp^{i+1}]	& (0<=i<=9)
	|   lexp^i
	|   rexp^i
lexp^i	->  exp^{i+1} op^{(l,i)} exp^{i+1}	& (0<=i<=9)
	|   lexp^i op^{(l,i)} exp^{i+1}
lexp^6	->  @-@ exp^7
rexp^i	->  exp^{i+1} op^{(r,i)} exp^{i+1}	& (0<=i<=9)
	|   exp^{i+1} op^{(r,i)} rexp^i
exp^{10} -> [exp^{10}] aexp			& (\tr{function application})

aexp	->  var					& (\tr{variable})
	|   con					& (\tr{constructor})
	|   literal				
	|   @()@				& (\tr{unit})
	|   @(@ exp @)@			      & (\tr{parenthesised expression})
	|   @(@ exp_1 @,@ ... @,@ exp_k @)@	& (\tr{tuple}, k>=2)
	|   @[@ exp_1 @,@ ... @,@ exp_k @]@	& (\tr{list}, k>=0)
	|   @[@ exp_1 [@,@ exp_2] @..@ [exp_3] @]@ & (\tr{arithmetic sequence})
	|   @[@ exp @|@ qual_1 @,@ ... @,@ qual_n @]@
 						& (\tr{list comprehension}, n>=1)


  *  [Pages~10, 13 and 119:] List comprehensions must have at least
one qualifier. 

aexp	->  @[@ exp @|@ qual_1 @,@ ... @,@ qual_n @]@
 						& (\tr{list comprehension}, n>=1)


  *  [Pages~13 and 119:] The nonterminal "qual" has been changed to
contain the syntax of just one qualifier.

qual	-> pat @<-@ exp 
         | exp 


  *  [Pages~15 and 119:] The syntax for @case@ has been changed to
allow for more than one guard per clause.

exp	->  @case@ exp @of@ @{@ alts @}@
alts	->  alt_1 @;@ ... @;@ alt_n		& (n>=1)
alt	->  pat @->@ exp [@where@ @{@ decls @}@]
	|   pat gdpat [@->@ exp] [@where@ @{@ decls @}@]
gdpat   ->  gd @->@ exp [ gdpat ]


  *  [Pages~21, 41, 117 and 120:] Contexts are no longer allowed in type
synonym declarations.   

topdecl -> @type@ simple @=@ type

itopdecl -> @type@ simple @=@ type


  *  [Pages~26, 32, 117 and 118:] The body of a class declaration
must have first all the signatures for the operations and then their
definitions. 

cbody	-> @{@ [csigns @;@] [valdefs [@;@]] @}@
csigns	-> [csign_1] @;@ ... @;@ [csign_n [@;@]]	& (n>=1)
csign	-> vars @::@ [context @=>@] type


valdefs ->  [valdef_1] @;@ ... @;@ [valdef_n [@;@]]	& (n>=1)


  *  [Pages~26, and 117:] Polymorphic class declarations are allowed.

  *  [Pages~27 and 118:] The rules for "inst" that refer to more than
one "tyvar" need a side-condition added: ``"tyvars" distinct''.

  *  [Pages~27 and 118:] The syntax for instances of function types
requires parentheses. 

inst	->  @(@ tyvar_1 @->@ tyvar_2 @)@		& tyvar_1 {\rm and} tyvar_2 {\rm distinct}


  *  [Pages~27 and 117:] Instance declaration can only have "valdefs"
in their body. 

topdecl -> @instance@ [context @=>@] tycls inst [@where@ @{@ valdefs @}@]


  *  [Pages~32 and 118:] Restrict WHERE expressions to the top-level
of a right-hand-side, and have them scope over equations with possibly
multiple guards. 

valdef	->  lhs @=@ exp [@where@ @{@ decls @}@]
	|   lhs gdfun [@=@ exp] [@where@ @{@ decls @}@]


  *  [Pages~32 and 118:] A final unguarded expression in "valdef" has
been added.

  *  [Pages~?? and 117:] The syntax for "renaming" has been fix to
reflect the one to one correspondence of "varid" and "conid".

  *  [Pages~41 and 120:] The @data@ rule for "itopdecl" changed so
that there is no @deriving@ clause if no constructors were exported. 

itopdecl-> @data@ [context @=>@] simple [@=@ constrs [@deriving@ (tycls | @(@tyclses@)@)]]


  *  [Pages~41 and 120:] Two forms of import in interface files are
now available.

ibody 	  -> @{@ [iimpdecls @;@] [iwimpdecls @;@] [fixdecls @;@] itopdecls @}@
 	   | @{@ \{ iimpdecls | iwimpdecls \} @}@
iimpdecls -> [iimpdecl_1] @;@ ... @;@ [iimpdecl_n [@;@]] & \qquad (n>=1) 
iimpdecl  -> @import@ modid @(@ import_1 @,@ ... @,@ import_n @)@ 
	   & [@renaming@ renamings] & \qquad (n>=1)
iwimpdecls-> [iwimpdecl_1] @;@ ... @;@ [iwimpdecl_n [@;@]] & \qquad (n>=1) 
iwimpdecl -> @import@ modid @(@ import_1 @,@ ... @,@ import_n @)@ 
	   & [@renaming@ renamings] @where@ @{@ iddecls @}@ & \qquad (n>=1)
iddecls	   -> [iddecl_1] @;@ ... @;@ [iddecl_n [@;@]] & (n>=1)
iddecl	   -> @data@ [context @=>@] simple [@=@ constrs [@deriving@ (tycls | @(@tyclses@)@)]]