2013-10-26 20 views
1

晚報,Haskell的錯誤 - 更PARAMATERS比需要

我具備的功能

partialDecode :: [(Char, Char)] -> String -> String 
partialDecode [] y = y -- If we have gone through all guesses we may return the string 
partialDecode x y = partialDecode (drop 1 x) replace ((fst (x !! 0) snd (x !! 0) y)) -- Recurse over the function: Drop the leading element in the list of guesses and substitute every occurrence of the guess in the string 

然而,當我運行ghci中返回一個錯誤說遞歸時,我提供3個paramters而不是2。我不確定這是什麼意思,我提供了一個元組清單(drop 1 x)和一個替換字符串((fst(x !! 0)snd(x !! 0)y))

建議?

乾杯!

+0

你應該閱讀錯誤消息更密切,他們攜帶有用的信息。當然關於「3個參數而不是2個」的錯誤也提到了*哪個函數被調用的參數個數錯誤。 – duplode

+0

另一個提示:x !! 0通常寫爲頭x。 –

回答

3

此:

partialDecode (drop 1 x) replace ((fst (x !! 0) snd (x !! 0) y)) 

通行證這些參數來partialDecode

  • (drop 1 x)
  • replace
  • ((fst (x !! 0) snd (x !! 0) y))

你可以reparenthesize它:

partialDecode x y = partialDecode (drop 1 x) (replace (fst (x !! 0) snd (x !! 0) y)) 

或者使用$

partialDecode x y = partialDecode (drop 1 x) $ replace (fst (x !! 0) snd (x !! 0) y) 

看起來像你應該做同樣的事情fstsnd,太:

partialDecode x y = partialDecode (drop 1 x) $ replace (fst $ x !! 0) (snd $ x !! 0) y 
+0

更改爲partialDecode x y = partialDecode(drop 1 x)$ replace(fst $ x !! 0))(snd $ x !! 0))y但仍然收到相同的錯誤 – MrD

+0

實際上,解決了!謝謝你的幫助! :d – MrD