-
5 votesanswersviews
Scala类型:A类不等于T所在的T:类型T = A.
我正在阅读“Scala编程”一书的第20.7节,我想知道为什么这段代码编译时: class Food class Fish extends Food class Grass extends Food abstract class Animal { type SuitableFood <: Food def eat(food: SuitableFood) } class Cow ... -
0 votesanswersviews
如何在不使用依赖类型的情况下进行模式匹配?
这很难说,所以请让我举个例子: trait Cache trait QueryLike { type Result } trait Query[A] extends QueryLike { type Result = A def exec: Result } trait CachedQuery[A] extends QueryLike { type Result = A ... -
3 votesanswersviews
依赖类型的工厂方法
我正在与Scala 2.11.7中的依赖类型进行斗争 . 以下是上下文: trait Counter { type T def zero: T def incr( t: T ): T } object IntCounter extends Counter { type T = Int val zero = 0 def incr( t: Int ) = t + 1 } ca... -
0 votesanswersviews
Scala中的抽象类型,变量和类型类
我正在尝试创建一个依赖于用户输入的类型类 . 想象一下,我们有一些案例对象: sealed trait H case object Ha extends H case object Hb extends H 和类型类: trait Foo[A] { def bar: String } object Foo { def bar[A : Foo] = implicitly[Foo[...