abstract-type

    0热度

    1回答

    我一直试图解决这个问题,但我似乎无法找到解决这个问题的方法。我似乎无法在Scala中正确建模。 可以说我有一个特征MyTrait与一些不可变的类实现它。 它看起来是这样的: trait MyTrait { type Repr <: MyTrait def substitute(original: Item, replacement: Item) : Repr de

    1热度

    1回答

    当我试图在斯卡拉在马丁·奥德斯基的编程抽象类型的动物/食品例, class Food abstract class Animal { type SuitableFood <: Food def eat(food:SuitableFood) } class Grass extends Food class Cow extends Animal { type Su

    0热度

    2回答

    我想访问“静态”的成员,以实现以下目标: abstract class Super { def typeSpecific: Int } class SubA extends Super { def typeSpecific = 1 } class SubB extends Super { def typeSpecific = 2 } class Tes

    1热度

    2回答

    我在Scala编程的第20.7章(Martin Odersky,Lex Spoon和Bill Venners)中有关于抽象类型主题的基本示例。下面的代码是从清单20.10,除了我添加了似乎表面上通过在前面的例子中隐含的最后两行: class Food abstract class Animal { type SuitableFood <: Food def eat(food:

    1热度

    1回答

    考虑下面的代码: abstract class Foobar { type Parent <: Foobar def parent: Option[Parent] } class Foo extends Foobar { type Parent = Nothing val parent = None // *** //

    2热度

    2回答

    我的情况是这样的: trait A { type B def foo(b: B) } trait C[D <: A] { val d: D def createB(): D#B def bar() { d.foo(createB) } } 在REPL,它抱怨 <console>:24: error: type mi

    0热度

    1回答

    我有这个用例我无法解决。 我想到了消息传递编程的环境。 有两个主要概念,事物和环境: 事情就像现实世界它们可以是被动或主动的,他们可以发送和接收消息。环境可以实现事物之间的沟通。 我想出了这个解决方案: /**** **** Thing.scala/ abstract class Thing(environment : Environment){ val uniqueName : Str

    1热度

    2回答

    考虑斗牛犬: trait Animal { type Food def defaultFood(): Food } class Bulldog extends Animal { type Food = Steak ... implementations ... } Bulldog.defaultFood()工作得很好的编译器(虽然我的语法高亮显

    1热度

    2回答

    我们有一个特质Foo和正在考虑的方法cast,需要一个类型参数A <: Foo和参数f: Foo并返回Some(f: A)如果f <: A,否则None类型: trait Foo def cast[A <: Foo](f: Foo): Option[A] = ??? 如果Foo extendings将永远是通用的,那么附加ClassTag是结论: def cast[A <: Foo : Cl

    3热度

    2回答

    可以说我们有一个特征,它具有一些值和一些操作。 trait Foo { type Self <: Foo val x: Int def withX(x: Int): Self } 这是使用抽象类型实现的。我们有一个绑定在Self上的类型,可以像这样实现: case class Foo1(x: Int) extends Foo { type Self =