Skip to content

Commit 6f21d93

Browse files
committed
Spec: Specify the desugaring of concrete refined types.
1 parent 978d4e4 commit 6f21d93

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/_spec/03-types.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,10 @@ ParamValueType ::= ParamValueType [‘*’]
10911091
TypeArgs ::= ‘[’ TypesOrWildcards ‘]’
10921092
Refinement ::= :<<< [RefineDcl] {semi [RefineDcl]} >>>
10931093
1094+
RefineDcl ::= ‘val’ ValDcl
1095+
| ‘def’ DefDcl
1096+
| ‘type’ {nl} TypeDcl
1097+
10941098
TypeBounds ::= [‘>:’ Type] [‘<:’ Type]
10951099
10961100
TypesOrWildcards ::= TypeOrWildcard {‘,’ TypeOrWildcard}
@@ -1152,3 +1156,28 @@ trait Function´_n´[-´T_1´, ..., -´T_n´, +´R´]:
11521156
```
11531157

11541158
Their exact supertype and implementation can be consulted in the [function classes section](./12-the-scala-standard-library.md#the-function-classes) of the standard library page in this document.
1159+
1160+
### Concrete Refined Types
1161+
1162+
```ebnf
1163+
RefinedType ::= AnnotType {[nl] Refinement}
1164+
SimpleType1 ::= ...
1165+
| Refinement
1166+
Refinement ::= :<<< [RefineDcl] {semi [RefineDcl]} >>>
1167+
1168+
RefineDcl ::= ‘val’ ValDcl
1169+
| ‘def’ DefDcl
1170+
| ‘type’ {nl} TypeDcl
1171+
```
1172+
1173+
In the concrete syntax of types, refinements can contain several refined declarations.
1174+
Moreover, the refined declarations can refer to each other as well as to members of the parent type, i.e., they have access to `this`.
1175+
1176+
In the abstract syntax of types, each refinement defines exactly one refined declaration, and references to `this` must be made explicit in a recursive type.
1177+
1178+
The conversion from the concrete syntax to the abstract syntax works as follows:
1179+
1180+
1. Create a fresh recursive this name ´\alpha´.
1181+
2. Replace every implicit or explicit reference to `this` in the refinement declarations by ´\alpha´.
1182+
3. Create nested [refined types](#refined-types), one for every refined declaration.
1183+
4. Unless ´\alpha´ was never actually used, wrap the result in a [recursive type](#recursive-types) `{ ´\alpha´ => ´...´ }`.

0 commit comments

Comments
 (0)