【发布时间】:2016-04-13 18:12:49
【问题描述】:
鉴于以下特征:
scala> trait Foo {
| def f: Int => Int => Int
| }
defined trait Foo
我创建了一个试图实例化Foo#f的类:
scala> class FooImpl extends Foo {
| override def f(x: Int, y: Int) = 100
| }
<console>:11: error: class FooImpl needs to be abstract, since method f in trait Foo of type => Int => (Int => Int) is not defined
class FooImpl extends Foo {
^
我能够通过以下方式解决它:
scala> class FooImpl extends Foo {
| override def f = x => y => 100
| }
defined class FooImpl
然后我可以做一个实例:
scala> new FooImpl().f(10)(20)
res3: Int = 100
但是,我将如何创建一个实现 Foo#f 和 def f(x: Int, y: Int) = 100 的 Foo,即没有柯里化?
最后,我试过了:
scala> trait Bar { def f: (Int, Int) => Int }
defined trait Bar
但这也失败了:
scala> class BarImpl extends Bar {
| override def f(x: Int, y:Int) =100
| }
<console>:11: error: class BarImpl needs to be abstract, since method f in trait Bar of type => (Int, Int) => Int is not defined
class BarImpl extends Bar {
^
【问题讨论】:
标签: scala