类型系统示例的Scala语法/语法?
我在学scala 在scala语法中,我读到了关于类型系统示例的Scala语法/语法?,scala,type-systems,Scala,Type Systems,我在学scala 在scala语法中,我读到了关于类型系统的内容 Type ::= FunctionArgTypes ‘=>’ Type | InfixType [ExistentialClause] FunctionArgTypes ::= InfixType | ‘(’ [ ParamType {‘,’ ParamType } ] ‘)’ Existent
类型系统的内容
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}
| ‘:’ ‘_’ ‘*’
我可以举一些例子:
当StableId
为Int
且StableId=>SimpleType=>AnnotType=>CompoundType=>InfixType=>Type
时,我们将得到一个名为Int
的类型
当FunctionArgTypes
为()
,Type
为Int
时,我们将得到一个名为()=>Int
的Type
当Type
为Array
,TypeArgs
为[Int]
时,我们将得到SimpleType
=Array[Int]
,然后Type
为Array[Int]
我不了解某些类型系统:
什么是InfixType
复合类型是什么
什么是优化
什么是归属
何时将SimpleType
派生SimpleType'#'id
,何时将派生'(“类型”)
有scala类型系统的例子吗
例如,Int-Op-String
中的Op
是中缀类型
trait Op[A, B]
type T = Int Op String
例如,带有布尔字符串的Int是一种复合类型
例如,{typex}
是
trait MyTrait
type T = MyTrait { type X }
例如,1:Int
中的:Int
是一种类型归属
例如,MyTrait#T
是一个类型投影
trait MyTrait {
type T
}
类型
是元组类型
你不能通过看语法来学习Scala,你需要遵循教程,看示例代码,然后自己尝试。@Tim,是的,但我真的想理解语法。你的问题是语义,而不是语法。符号的名称与语法无关,它们只是用来暗示将要应用的语义解释。例如,InfixType
也可以是CuddlyToy
,语法将保持不变。为什么要学习该语言的语法?它是为编译器团队和希望为该语言编写元工具的人准备的,不是为新手准备的。@jwvh只是想在scala编译器中学习一些东西
type T = (Int, String, Boolean)