Optional bar before first match clause

From Successor ML

Jump to: navigation, search

Contents

Introduction

We propose a minor syntax extension to allow an optional bar before the first clause in a match.

Motivation

SML syntax separates match clauses with a bar "|". The usual coding convention is to lay out matches such that the bar comes before each clause. However, the first clause is an unpleasent special case:

   case exp0 of
       pat1 => exp1
     | pat2 => exp2
     | pat3 => exp3

Taking aesthethic considerations aside, the assymmetry between the cases is a nuisance for editing, because clauses cannot be reordered by a simple cut & paste operation. We hence propose allowing an additional bar to optionally appear before the first clause, such that the above can be written as:

   case exp0 of
     | pat1 => exp1
     | pat2 => exp2
     | pat3 => exp3

For consistency, we make the same extension for function value bindings, and for datatype declarations. For instance,

   datatype 'a exp =
     | Const  of 'a
     | Var    of string
     | Lambda of string * 'a exp
     | App    of 'a exp * 'a exp

A similar extension has been made in Objective Caml.

Assumptions

None.

Syntax

Defined by the following modifications to the Definition:

  • In Section 2.8, Figure 4, and Appendix B, Figure 20, change the productions for exception handling, functions, and case expressions (only in the latter figure) to, respectively:
   [exp ::=]    exp "handle" <"|"> match         handle exception
                "fn" <"|"> match                 function
                "case" exp "of" <"|"> match      case analysis
  • In Section 2.8, Figure 4, and Appendix B, Figure 21, change the production for datatype bindings to:
   datbind ::=  tyvarseq tycon "=" <"|"> conbind <"and" datbind>
  • In Section 3.4, Figure 7, change the productions for datatype descriptions to:
   datdesc ::=  tyvarseq tycon "=" <"|"> condesc <"and" datdesc>
  • In Appendix A, Figure 15, change the rule for case expressions to
   +-----------------------+---------------------+
   | case exp of <|> match | (fn <|> match)(exp) |
   +-----------------------+---------------------+
  • In Figure 17, change the first line in the definition of function clauses to
   +------------------------------------------------+-------------------------------------------+
   |                                                | [...]                                     |
   | <|> <op>vid atpat11 ... atpat1n <: ty1> = exp1 | <|> (atpat11,...,atpat1n) => exp1 <: ty1> |
   | [...]                                          | [...]                                     |
   +------------------------------------------------+-------------------------------------------+
  • In Appendix B, Figure 21, change the production for fvalbind accordingly.

Static Semantics

Defined by the following modifications to the Definition:

  • In Section 4.10, Expressions, modify the syntax in the conclusion of rules 10 and 12 accordingly.

Dynamic Semantics

Defined by the following modifications to the Definition:

  • In Section 6.7, Expressions, modify the syntax in the conclusion of rules 104-106 and 108 accordingly.

Interactions

None.

Compatibility

This is a conservative change.

Implementation

Trivial.

Personal tools