I'm learning scala.
In scala syntax: https://www.scala-lang.org/files/archive/spec/2.13/13-syntax-summary.html, I read about the type system.
Type ::= FunctionArgTypes ‘=>’ Type
| InfixType [ExistentialClause]
FunctionArgTypes ::= InfixType
| ‘(’ [ ParamType {‘,’ ParamType } ] ‘)’
ExistentialClause ::= ‘forSome’ ‘{’ ExistentialDcl {semi ExistentialDcl} ‘}’
ExistentialDcl ::= ‘type’ TypeDcl
| ‘val’ ValDcl
InfixType ::= CompoundType {id [nl] CompoundType}
CompoundType ::= AnnotType {‘with’ AnnotType} [Refinement]
| Refinement
AnnotType ::= SimpleType {Annotation}
SimpleType ::= SimpleType TypeArgs
| SimpleType ‘#’ id
| StableId
| Path ‘.’ ‘type’
| ‘(’ Types ‘)’
TypeArgs ::= ‘[’ Types ‘]’
Types ::= Type {‘,’ Type}
Refinement ::= [nl] ‘{’ RefineStat {semi RefineStat} ‘}’
RefineStat ::= Dcl
| ‘type’ TypeDef
|
TypePat ::= Type
Ascription ::= ‘:’ InfixType
| ‘:’ Annotation {Annotation}
| ‘:’ ‘_’ ‘*’
I can give some examples:
- when
StableIdisInt, andStableId => SimpleType => AnnotType => CompoundType => InfixType => Type, we will get aTypecalledInt. - when
FunctionArgTypesis(),TypeisInt, we will get aTypecalled()=>Int. - when
TypeisArray,TypeArgsis[Int], we will getSimpleType=Array[Int], thenTypeisArray[Int].
I don't understand some of the type system:
- What's the
InfixType? - What's the
CompoundType? - What's the
Refinement? - What's the
Ascription? - When will
SimpleTypederive aSimpleType '#' id, and when will derive'(' Types ')'?
Is there any examples for scala type system ?