Skip to content

Commit 6021b7b

Browse files
committed
Make it clear that variance in concrete type lambdas are inferred.
1 parent 8657620 commit 6021b7b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

docs/_spec/03-types.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ FunctionArgTypes ::= InfixType
1818
FunParamClause ::= ‘(’ TypedFunParam {‘,’ TypedFunParam } ‘)’
1919
TypedFunParam ::= id ‘:’ Type
2020
TypeLambda ::= TypeLambdaParams ‘=>>’ Type
21-
TypeLambdaParams ::= ‘[’ TypeLambdaParam {‘,’ TypeLambdaParam} ‘]’
22-
TypeLambdaParam ::= {Annotation} (id | ‘_’) [TypeParamClause] TypeBounds
2321
InfixType ::= RefinedType
2422
| RefinedTypeOrWildcard id [nl] RefinedTypeOrWildcard {id [nl] RefinedTypeOrWildcard}
2523
RefinedType ::= AnnotType {[nl] Refinement}
@@ -47,6 +45,11 @@ ParamValueType ::= ParamValueType [‘*’]
4745
TypeArgs ::= ‘[’ TypesOrWildcards ‘]’
4846
Refinement ::= :<<< [RefineDcl] {semi [RefineDcl]} >>>
4947
48+
TypeLambdaParams ::= ‘[’ TypeLambdaParam {‘,’ TypeLambdaParam} ‘]’
49+
TypeLambdaParam ::= {Annotation} (id | ‘_’) [TypeParamClause] TypeBounds
50+
TypeParamClause ::= ‘[’ VariantTypeParam {‘,’ VariantTypeParam} ‘]’
51+
VariantTypeParam ::= {Annotation} [‘+’ | ‘-’] (id | ‘_’) [TypeParamClause] TypeBounds
52+
5053
RefineDcl ::= ‘val’ ValDcl
5154
| ‘def’ DefDcl
5255
| ‘type’ {nl} TypeDcl
@@ -225,6 +228,21 @@ The conversion from the concrete syntax to the abstract syntax works as follows:
225228
3. Create nested [refined types](#refined-types), one for every refined declaration.
226229
4. Unless ´\alpha´ was never actually used, wrap the result in a [recursive type](#recursive-types) `{ ´\alpha´ => ´...´ }`.
227230

231+
### Concrete Type Lambdas
232+
233+
```ebnf
234+
TypeLambda ::= TypeLambdaParams ‘=>>’ Type
235+
TypeLambdaParams ::= ‘[’ TypeLambdaParam {‘,’ TypeLambdaParam} ‘]’
236+
TypeLambdaParam ::= {Annotation} (id | ‘_’) [TypeParamClause] TypeBounds
237+
TypeParamClause ::= ‘[’ VariantTypeParam {‘,’ VariantTypeParam} ‘]’
238+
VariantTypeParam ::= {Annotation} [‘+’ | ‘-’] (id | ‘_’) [TypeParamClause] TypeBounds
239+
```
240+
241+
At the top level of concrete type lambda parameters, variance annotations are not allowed.
242+
However, in internal types, all type lambda parameters have explicit variance annotations.
243+
244+
When translating a concrete type lambda into an internal one, the variance of each type parameter is _inferred_ from its usages in the body of the type lambda.
245+
228246
## Definitions
229247

230248
From here onwards, we refer to internal types by default.

0 commit comments

Comments
 (0)