2015-09-04 64 views
0
我有我的凿子代码中的问题

,我尝试以下方法凿编程错误

deqReg   := Cat((0 until ports).map(ownReg === Cat(io.configVal(portBits*(_) + 2),io.configVal(portBits*(_)+ 1), io.configVal(portBits*(_))))) 

但在运行上面的代码时,我收到以下错误

[error] /home/jayant/Dropbox/FIFO/fifo.scala:24: missing parameter type for expanded function ((x$1) => portBits.$times(x$1).$plus(2)) 
[error]  deqReg   := Cat((0 until ports).map(ownReg === Cat(io.configVal(portBits*(_) + 2),io.configVal(portBits*(_)+ 1), io.configVal(portBits*(_))))) 
[error]                     ^
[error] one error found 
[error] (compile:compileIncremental) Compilation failed 
[error] Total time: 2 s, completed 4 Sep, 2015 12:31:40 PM 

任何一个可以告诉这个错误是什么以及如何纠正它。

回答

2

在映射中有多个嵌套函数会使Scala编译器无法推断参数的类型。换句话说,你不能在这里使用“_”占位符。占位符只是替换表达式中最内层函数的参数。尝试完全指定的匿名函数(或部分功能)是这样的:

deqReg := Cat((0 until ports).map{ case i:Int => ownReg === Cat(io.configVal(portBits*i + 2), io.configVal(portBits*i + 1), io.configVal(portBits*i))}) 

Scala是一个非常强大的语言,你最可能能够找到一个更优雅的方式编写代码。

+0

谢谢,它确实为我工作。 –

+0

不客气:)你会考虑接受答案吗?让我知道你是否需要更多信息! – Kamyar