如何在Scala中编写类型推断案例

时间:2017-10-08 10:27:13

标签: scala

我关注HipsterTree.scala文件。使用此文件,如何在以下位置定义类型推理的案例:

val tipe : Expression => Type =
attr {
  case IdnExpr(i) =>
    entity(i) match {
      case e : Applicable => UnknownType()
      case e : TypedEntity => e.tipe
      case _ => UnknownType()
    }
  case _ : IntExpr => IntType()
  case _ : FloatExpr => FloatType()
  case _ : BoolExpr => BoolType()

  // FIXME: Add type inference cases for all other expression
  // node types here.

  case _ => UnknownType()
}

  val expTipe : Expression => Set[Type] =
attr {
  // Expected types of dimension expressions.
  case tree.parent(_ : BoundedDim) => Set(IntType())
  case tree.parent(_ : CyclicDim) => Set(IntType())

  case tree.parent.pair(n, ConstantDecl(t,_,_)) =>
    compatTypes(t)
  case tree.parent.pair(n, VarDecl(t,_,_)) =>
    compatTypes(t)

  // FIXME: Add cases to compute the set of expected types for an
  // expression node by inspecting the type of its parent.
  // with the computed expression type.
  case n => compatTypes(tipe(n))
}

我很感激能帮助我添加FIXME指示

的案例的任何人

0 个答案:

没有答案
相关问题