首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Scala语法/语法类型系统示例?

Scala语法/语法类型系统示例?
EN

Stack Overflow用户
提问于 2020-08-07 05:59:07
回答 1查看 88关注 0票数 2

我在学斯卡拉。

在scala语法:https://www.scala-lang.org/files/archive/spec/2.13/13-syntax-summary.html中,我读到了关于type system的文章。

代码语言:javascript
复制
  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.

  • when ()=>Int.

  • when D20是ArrayTypeArgs[Int],我们将得到SimpleType = Array[Int],然后d26是Array[Int].

>D26Array[Int].>。

我不明白某些类型的系统:

  1. InfixType
  2. 是什么?
  3. 是什么?H 239H 140 Ascription?<InfixType>H 242H 143D44什么时候派生d45,以及什么时候将派生'(' Types ')'?H 247G 248

scala类型系统有什么示例吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-07 13:31:03

例如,

  1. Int Op String中的Op是一个infix类型。

性状OpA,B型T= Int Op String

例如,

  1. Int with String with Boolean是一种复合类型。

例如,

性状MyTrait类型T= MyTrait {X }

例如,

  1. ( : Int in 1 : Int )是一种类型归属。

例如,

  1. MyTrait#T是一个类型投影。

性状MyTrait {T}

类型

类型T= (Int,String,Boolean)

是元组类型。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63296049

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档