私は現在、haskell のボード評価に取り組んでいます。複数のパラメーターを持つ関数で map を使用しようとしています。これに関する他のSOの質問を読みましたが、型エラーが発生し続けるため、おそらくHaskell型を誤解しているだけです(私はPythonプログラマーです)。いずれにせよ、コードは次のとおりです。
scorePiecesRow [] _ = 0
scorePiecesRow (x:xs) y
| x == y = 1 + (scorePiecesRow xs y)
| x == '-' = 0 + (scorePiecesRow xs y)
| otherwise = -1 + (scorePiecesRow xs y)
scorePieces [] _ = 0
scorePieces board y = foldr (+) 0 (map (scorePiecesRow y) board)
scorePiecesRow"wwwb--" 'w'(これは を返します) のようなものを渡すと問題なく動作しますが、 (たとえば、 を返す必要がある)3を呼び出すとすぐに、一連の型エラーが発生します。scorePiecesscorePieces ["www", "bb-"] 'w'1
<interactive>:37:14: Couldn't match expected type `Char' with actual type `[Char]' In the expression: "www" In the first argument of `scorePieces', namely `["www", "bb-"]' In the expression: scorePieces ["www", "bb-"] 'w' <interactive>:37:21: Couldn't match expected type `Char' with actual type `[Char]' In the expression: "bb-" In the first argument of `scorePieces', namely `["www", "bb-"]' In the expression: scorePieces ["www", "bb-"] 'w' <interactive>:37:28: Couldn't match expected type `[Char]' with actual type `Char' In the second argument of `scorePieces', namely 'w' In the expression: scorePieces ["www", "bb-"] 'w' In an equation for `it': it = scorePieces ["www", "bb-"] 'w'
エラーメッセージに少し混乱しています。たとえば、最初のものは、それが expected であることを示していCharますが、の最初の引数はscorePiecesRowtake[Char]です。誰かがこれに光を当てることができれば、それは大歓迎です!