Derived "do" declarations

From Successor ML

Jump to: navigation, search

Contents

Introduction

We propose adding declarations of the form "do exp" that evaluate their argument solely for its side effects.

Motivation

A very frequent idiom in SML are declarations of the form

  val _ = exp

which are used to evaluate an expression for its side effects. This idiom is somewhat verbose and ugly.

On the toplevel, expressions can be evaluated by simply writing them in place of a declaration (which abbreviates a declaration of "it"). However, this form is not available in local scope, and moreover does require putting a semicolon before and after the expression, which is somewhat counterintuitive. This form only is useful in a REPL.

We propose a new derived form that simply abbreviates "val () =" with the keyword "do".

Assumptions

None.

Syntax

Defined by the following modifications to the Definition:

  • In Appendix A, Figure 17, add the following to the Declarations box:
   +----------+--------------+
   | do exp   | val () = exp |
   +----------+--------------+
  • In Appendix B, Figure 21, add the following production for declarations:
   [dec ::=] do exp     evaluation

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 change.

Implementation

Trivial.

Personal tools