我在学斯卡拉。
在scala语法:https://www.scala-lang.org/files/archive/spec/2.13/13-syntax-summary.html中,我读到了关于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}
| ‘:’ ‘_’ ‘*’我可以举几个例子:
当Int.
()=>Int.
Array,TypeArgs是[Int],我们将得到SimpleType = Array[Int],然后d26是Array[Int].
>D26Array[Int].>。
我不明白某些类型的系统:
InfixType?H 239H 140 Ascription?<InfixType>H 242H 143D44什么时候派生d45,以及什么时候将派生'(' Types ')'?H 247G 248scala类型系统有什么示例吗?
发布于 2020-08-07 13:31:03
例如,
Int Op String中的Op是一个infix类型。性状OpA,B型T= Int Op String
例如,
Int with String with Boolean是一种复合类型。例如,
性状MyTrait类型T= MyTrait {X }
例如,
: Int in 1 : Int )是一种类型归属。例如,
MyTrait#T是一个类型投影。性状MyTrait {T}
类型
类型T= (Int,String,Boolean)
是元组类型。
https://stackoverflow.com/questions/63296049
复制相似问题