これは本当にうっとうしい質問かもしれませんが、私はこの問題を克服できません。予想されるタイプの `Text 'と実際のタイプ` [Char]'を一致させることができませんでした。
私は、コードの単純なブロックがあります。私はstr
でこれを呼び出すと、私が手
module SomeTest where
import Data.Text
str = replace "ofo" "bar" "ofofo"
を:
<interactive>:108:19: error: * Couldn't match expected type `Text' with actual type `[Char]' * In the first argument of `Data.Text.replace', namely `"ofo"' In the expression: Data.Text.replace "ofo" "bar" "ofofo" In an equation for `it': it = Data.Text.replace "ofo" "bar" "ofofo" <interactive>:108:25: error: * Couldn't match expected type `Text' with actual type `[Char]' * In the second argument of `Data.Text.replace', namely `"bar"' In the expression: Data.Text.replace "ofo" "bar" "ofofo" In an equation for `it': it = Data.Text.replace "ofo" "bar" "ofofo" <interactive>:108:31: error: * Couldn't match expected type `Text' with actual type `[Char]' * In the third argument of `Data.Text.replace', namely `"ofofo"' In the expression: Data.Text.replace "ofo" "bar" "ofofo" In an equation for `it': it = Data.Text.replace "ofo" "bar" "ofofo"
私は取得していますなぜ私にはわかりませんこのエラーとどのようにそれを渡す得る。 Text
は[Char]
の単なる同義語ではありませんか?
いいえ、「テキスト」は完全に異なるタイプです。しかし、 'String'は' [Char] 'の同義語です。 – melpomene
残念ながら、Haskellには文字列にいくつかの相反するタイプがあります。あなたの場合は、プログラムの最初の行に '{ - #LANGUAGE OverloadedStrings# - }'を追加するとコンパイルするはずです。 – stholzm
ありがとう、これは実際に働いた。このコメントから回答をしてください、私はそれを受け入れます。 –