【发布时间】:2020-06-19 19:01:56
【问题描述】:
我正在尝试在脚本中编写 2 个函数,但遇到了我无法解决的类型不匹配问题。 这是示例代码:
def generate(start: Int, end: Int): Seq[Int] = (start until end).toSeq
def restrain(seq: Seq[Int]) = seq.dropWhile(_ < 20).takeWhile(_ < 60)
val com: (Int, Int) => Seq[Int] = (restrain _ compose generate)
通过在 REPL 中加载它:
:load test.sc
我收到以下错误:
val com: (Int, Int) => Seq[Int] = (restrain _ compose generate)
^
test.sc:1: error: type mismatch;
found : (Int, Int) => Seq[Int]
required: ? => Seq[Int]
我做错了什么?
【问题讨论】:
-
另外,请参阅this answer(即使它回答了不同的问题)。
标签: scala type-systems function-composition