Skip to content
  • Simon Peyton Jones's avatar
    [project @ 2003-06-24 07:58:18 by simonpj] · 16e4ce4c
    Simon Peyton Jones authored
    ----------------------------------------------
    	Add support for Ross Paterson's arrow notation
    	----------------------------------------------
    
    Ross Paterson's ICFP'01 paper described syntax to support John Hughes's
    "arrows", rather as do-notation supports monads.  Except that do-notation is
    relatively modest -- you can write monads by hand without much trouble --
    whereas arrow-notation is more-or-less essential for writing arrow programs.
    It desugars to a massive pile of tuple construction and selection!
    
    For some time, Ross has had a pre-processor for arrow notation, but the
    resulting type error messages (reported in terms of the desugared code)
    are impenetrable.  This commit integrates the syntax into GHC.  The
    type error messages almost certainly still require tuning, but they should
    be better than with the pre-processor.
    
    Main syntactic changes (enabled with -farrows)
    
       exp ::= ... | proc pat -> cmd
    
       cmd ::= exp1 -<  exp2   |  exp1 >-  exp2
    	|  exp1 -<< exp2   |  exp1 >>- exp2
    	| \ pat1 .. patn -> cmd
    	| let decls in cmd
    	| if exp then cmd1 else cmd2
    	| do { cstmt1 .. cstmtn ; cmd }
    	| (| exp |) cmd1 .. cmdn
    	| cmd1 qop cmd2
    	| case exp of { calts }
    
       cstmt :: = let decls
    	 |   pat <- cmd
    	 |   rec { cstmt1 .. cstmtn }
    	 |   cmd
    
    New keywords and symbols:
    	proc rec
    	-<   >-   -<<   >>-
    	(|  |)
    
    The do-notation in cmds was not described in Ross's ICFP'01 paper; instead
    it's in his chapter in The Fun of Programming (Plagrave 2003).
    
    The four arrow-tail forms (-<) etc cover
      (a) which order the pices come in (-<  vs  >-), and
      (b) whether the locally bound variables can be used in the
    		arrow part (-<  vs  -<<) .
    In previous presentations, the higher-order-ness (b) was inferred,
    but it makes a big difference to the typing required so it seems more
    consistent to be explicit.
    
    The 'rec' form is also available in do-notation:
      * you can use 'rec' in an ordinary do, with the obvious meaning
      * using 'mdo' just says "infer the minimal recs"
    
    
    Still to do
    ~~~~~~~~~~~
    Top priority is the user manual.
    
    The implementation still lacks an implementation of
    the case form of cmd.
    
    
    Implementation notes
    ~~~~~~~~~~~~~~~~~~~~
    Cmds are parsed, and indeed renamed, as expressions.  The type checker
    distinguishes the two.
    16e4ce4c