Skip to content

Commit

Permalink
Add specification for type synonyms in DAML-LF (#3635)
Browse files Browse the repository at this point in the history
* Add specification for type synonyms in DAML-LF

* Fix identifiers for type synonyms

* Use S for type synonyms

* Address review comments

* Split up TyTypeSynonym and DefTypeSynonym
  • Loading branch information
cocreature authored and mergify[bot] committed Nov 26, 2019
1 parent 06b7a10 commit f402acf
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions daml-lf/spec/daml-lf-1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ Version: 1.dev

* **Rename** ``Map`` to ``TextMap``

* **Add** type synonyms.

Abstract syntax
^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -474,8 +476,8 @@ future addition to allowed identifier characters.

In the following, we will use identifiers to represent *built-in
functions*, term and type *variable names*, record and tuple *field
names*, *variant constructors*, and *template choices*. On the other
hand, we will use names to represent *type constructors*, *value
names*, *variant constructors* and *template choices*. On the other
hand, we will use names to represent *type constructors*, *type synonyms*, *value
references*, and *module names*. Finally, we will use PackageId
strings as *package identifiers*. ::

Expand Down Expand Up @@ -506,6 +508,9 @@ strings as *package identifiers*. ::
Type constructors
T ::= Name -- TyConName

Type synonym names
S ::= Name -- TypeSynonym

Module names
ModName ::= Name -- ModName

Expand Down Expand Up @@ -676,6 +681,7 @@ available for usage::
| 'variant' T (α₁: k₁)… (αₙ: kₙ) ↦ V₁ : τ₁ | … | Vₘ : τₘ
-- DefVariant
| 'enum' T ↦ E₁ | … | Eₘ -- DefEnum
| 'synonym' S (α₁: k₁)… (αₙ: kₙ) ↦ τ -- DefTypeSynonym
| 'val' W : τ ↦ e -- DefValue
| 'tpl' (x : T) ↦ -- DefTemplate
{ 'precondition' e₁
Expand Down Expand Up @@ -846,6 +852,13 @@ First, we formally defined *well-formed types*. ::
————————————————————————————————————————————— TyTuple
Γ ⊢ ⟨ f₁: τ₁, …, fₙ: τₙ ⟩ : ⋆

'synonym' S (α₁:k₁) … (αₙ:kₙ) ↦ τ ∈ 〚Ξ〛Mod
Γ ⊢ τ₁ : k₁ … Γ ⊢ τₙ : kₙ
————————————————————————————————————————————— TyTypeSynonym
Γ ⊢ S τ₁ … τₙ : ⋆




Well-formed expression
......................
Expand Down Expand Up @@ -982,6 +995,12 @@ Then we define *well-formed expressions*. ::
——————————————————————————————————————————————————————————————— ExpEnumCon
Γ ⊢ Mod:T:Eᵢ : Mod:T

'synonym' S (α₁:k₁) … (αₙ:kₙ) ↦ τ
Γ ⊢ τ₁ : k₁ ⋯ Γ ⊢ τₙ : kₙ
Γ ↦ e : τ[α₁ ↦ τ₁, …, α₁ ↦ τₙ]
——————————————————————————————————————————————————————————————— ExpTypeSynonym
Γ ⊢ e : Mod:S τ₁ … τₙ

Γ ⊢ e₁ : τ₁ … Γ ⊢ eₘ : τₘ
——————————————————————————————————————————————————————————————— ExpTupleCon
Γ ⊢ ⟨ f₁ = e₁, …, fₘ = eₘ ⟩ : ⟨ f₁: τ₁, …, fₘ: τₘ ⟩
Expand Down Expand Up @@ -1219,6 +1238,10 @@ for the ``DefTemplate`` rule). ::
——————————————————————————————————————————————————————————————— DefEnum
⊢ 'enum' T ↦ E₁ | … | Eₘ

(α₁:k₁) … (αₙ:kₙ) · Γ ⊢ τ : ⋆
——————————————————————————————————————————————————————————————— DefTypeSynonym
⊢ 'synonym' S (α₁: k₁) … (αₙ: kₙ) ↦ τ

ε ⊢ e : τ
——————————————————————————————————————————————————————————————— DefValue
⊢ 'val' W : τ ↦ e
Expand Down

0 comments on commit f402acf

Please sign in to comment.