Record labels as fields

From Successor ML

Jump to: navigation, search

Contents

Introduction

We propose a simple abbreviated syntactic form for constructing records.

Motivation and Example

SML allows record patterns of the form {a=a, b=b, ...} to be abbreviated conveniently as {a, b, ...} (sometimes called "punning"). The same abbreviation is not currently provided for record expressions. Such an abbreviation can be equally convenient, e.g. for constructing records from local variables:

   fun circle (x,y,r) =
       let
           val x = ref x and y ref y and r = ref r
           fun pos () = (!x,!y)
           fun radius () = !r
           fun move (dx,dy) = (x := !x+dx, y := !y+dy)
           fun scale s = (r := !r*s)
       in
           {pos, radius, move, scale}
       end

Assumptions

None.

Syntax

Defined by the following modifications to the Definition:

  • In Appendix A, Figure 15, add the following box:
   Expression Rows exprow
   +-----------------------+-----------------------------+
   | vid <: ty> <, exprow> | vid = vid <: ty> <, exprow> |
   +-----------------------+-----------------------------+
  • In Appendix B, Figure 20, add the following production:
   [exprow ::=]    vid <: ty> <, exprow>    label as variable

Static Semantics

Follows from the definition as a derived form.

Dynamic Semantics

Follows from the definition as a derived form.

Interactions

None.

Compatibility

This is a conservative extension.

Implementation

Trivial.

Personal tools