1

夜、

私は機能を持っています

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

ただし、実行すると、再帰時に 2 つではなく 3 つのパラメーターを指定していることを示すエラーが ghci から返されます。これが何を意味するのかわかりません。(drop 1 x) でタプルのリストを提供し、replace ((fst (x !! 0) snd (x !! 0) y)) で文字列を提供しています。

提案?

乾杯!

4

1 に答える 1

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))

括弧を付け直すことができます:

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)

fstandでも同じことを行う必要があるようですsnd

partialDecode x y = partialDecode (drop 1 x) $ replace (fst $ x !! 0) (snd $ x !! 0) y
于 2013-10-26T18:12:46.507 に答える