Skip to content

Commit

Permalink
Add back table<T> type descriptors
Browse files Browse the repository at this point in the history
Fixes #153.
  • Loading branch information
jclark committed May 31, 2019
1 parent 906d0da commit 5dad364
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
31 changes: 17 additions & 14 deletions lang/spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,10 @@ <h4>[Preview] Tables</h4>
</p>

<pre
class="grammar">table-type-descriptor := <code>table</code> <code>{</code> column-type-descriptor+ <code>}</code>
class="grammar">table-type-descriptor := direct-table-type-descriptor | indirect-table-type-descriptor
direct-table-type-descriptor := <code>table</code> <code>{</code> column-type-descriptor+ <code>}</code>
indirect-table-type-descriptor := <code>table</code> type-parameter

column-type-descriptor :=
individual-column-type-descriptor
| column-record-type-reference
Expand All @@ -1039,13 +1042,20 @@ <h4>[Preview] Tables</h4>
column-name := identifier
</pre>
<p>
A table type descriptor has a descriptor for each column, which specifies the
A direct-table-type-descriptor has a descriptor for each column, which specifies the
name of the column, whether that column is part of a primary key and the type
that values in that column must belong to. The type descriptor for the column
must be a pure type. If a column is part of a primary key, then the type
descriptor for the column must also allow only non-nil simple values.
</p>
<p>
An indirect-table-type-descriptor describes a table type in terms of the shape
of the the rows of the table. A type <code>table&lt;T&gt;</code> contains a
table shape if <code>T</code> contains the mapping shape of every member of the
table shape. If <code>T</code> is a closed record type, then
<code>table&lt;T&gt;</code> is equivalent to <code>table { *T; }</code>.
</p>
<p>
Note that a table type T' will be a subtype of a table type T if and only if:
</p>
<ul>
Expand All @@ -1055,19 +1065,10 @@ <h4>[Preview] Tables</h4>
that column in T.</li>
</ul>
<p>
A table is iterable as a sequence of mapping values, one for each row, where
each mapping value has a field for each column, with the column as the field
name and the value of that column in that row as the field value. The mapping
values will belong to a closed record type.
</p>
<p>
Issues:
A table is iterable as a sequence of mapping values, one for each row; the
inherent type of each mapping value will be a closed record type.
</p>
<ul>
<li>Need to say that unique constraint is part of the value.</li>
<li>Do we want to allow values that are distinct but numerically equal e.g. -0.0
and +0.0 or 1.0 and 1 in primary key columns?</li>
</ul>

<h4>XML</h4>

<pre class="grammar">xml-type-descriptor := <code>xml</code>
Expand Down Expand Up @@ -5340,6 +5341,8 @@ <h3>Summary of changes from 2019R1 to 2019R2</h3>
rather than as a sequence of key-value pairs. The <code>entries</code> lang library
function allows it to be iterated as a sequence of key-value pairs.</li>
<li>The basic type <code>handle</code> has been added.</li>
<li>The <code>table&lt;T&gt;</code> type descriptor shorthand has been brought
back.</li>
</ol>

<h3>Summary of changes from 0.990 to 2019R1</h3>
Expand Down
30 changes: 30 additions & 0 deletions langlib/table.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2019 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
//
// WSO2 Inc. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.


# The type bound for a table row.
# Note that this is equivalent to `map<anydata|error>`.
@typeParam
private type RowType = record { };

# Returns number of members in `tbl`.
public function length(table<record { }> tbl) returns int = external;
# Returns an iterator over the members of `tbl`.
public function iterator(table<RowType> tbl) returns abstract object {
public next() returns record {|
RowType value;
|}?;
} = external;

0 comments on commit 5dad364

Please sign in to comment.