next up previous
Next: 4.3 Example Translation Up: 4 Example Previous: 4.1 Example DSL Syntax

4.2 Example DSL Semantics

DSL values have types drawn from $D = \mbox{\textbf{Int}} \vert \mbox{Seq}(D)$.We define, $\forall n \in \mbox{\textbf{Int}}, c \in D$:

\begin{displaymath}
\mbox{\tt range}(n) = \mbox{\tt (/}\ 1, 2, \ldots, n \ \mbox{\tt /)}\end{displaymath}

\begin{displaymath}
\mbox{\tt dist}(c,n) = \mbox{\tt (/}\ c, c, \ldots, c \ \mbox{\tt /)}\end{displaymath}

with $\mbox{\tt length}(\mbox{\tt dist}(c,n)) = \mbox{\tt length}(\mbox{\tt range}(n)) = n$.For an expression, e, the sequence comprehension

\begin{displaymath}
\mbox{\tt (/}\ i \ \mbox{\tt in}\ A \ \mbox{\tt :}\ e(i) \ \mbox{\tt /)}\end{displaymath}

yields the sequence of successive values of e obtained when i is bound to successive values in A.

For example, the sample program: 

        A = range(3);
        B = (/ i in A: i + i /);
        C = (/ i in A:
               (/ j in range(i): i /) /)

yields:

        A = (/ 1, 2, 3 /)
        B = (/ 2, 4, 6 /)
        C = (/ (/ 1 /),
               (/ 2, 2 /),
               (/ 3, 3, 3 /) /)

We omit here a collection of type (inference) rules for the language that define a well-typed program.



Rickard Faith
8/31/1997