Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
类型系统示例的Scala语法/语法?_Scala_Type Systems - Fatal编程技术网

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

类型系统示例的Scala语法/语法?,scala,type-systems,Scala,Type Systems,我在学scala 在scala语法中,我读到了关于类型系统的内容 Type ::= FunctionArgTypes ‘=>’ Type | InfixType [ExistentialClause] FunctionArgTypes ::= InfixType | ‘(’ [ ParamType {‘,’ ParamType } ] ‘)’ Existent

我在学scala

在scala语法中,我读到了关于
类型系统的内容

  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)