带柯里化的默认参数
我可以将一个函数定义为:
def print(n:Int, s:String = "blah") {}
print: (n: Int,s: String)Unit
我可以用以下方式调用它:
print(5)
print(5, "testing")
如果我柯里化上面的内容:
def print2(n:Int)(s:String = "blah") {}
print2: (n: Int)(s: String)Unit
我不能用 1 个参数调用它:
print2(5)
<console>:7: error: missing arguments for method print2 in object $iw;
follow this method with `_' if you want to treat it as a partially applied function
print2(5)
我必须提供两个参数。有办法解决这个问题吗?
I can define a function as:
def print(n:Int, s:String = "blah") {}
print: (n: Int,s: String)Unit
I can call it with:
print(5)
print(5, "testing")
If I curry the above:
def print2(n:Int)(s:String = "blah") {}
print2: (n: Int)(s: String)Unit
I can't call it with 1 parameter:
print2(5)
<console>:7: error: missing arguments for method print2 in object $iw;
follow this method with `_' if you want to treat it as a partially applied function
print2(5)
I have to supply both parameters. Is there some way around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能使用默认参数省略
()
:尽管它适用于隐式:
You can't omit
()
with default arguments:Though it works with implicits: