2015-09-04 60 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