Questa potrebbe essere una domanda davvero noobish, ma non riesco a superare questo problema (dato che ho appena iniziato ad imparare Haskell).Impossibile corrispondere al tipo atteso `Testo 'con tipo effettivo` [Char]'
Ho un semplice blocco di codice:
module SomeTest where
import Data.Text
str = replace "ofo" "bar" "ofofo"
Se chiamo questo con str
, ottengo:
<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"
Non so il motivo per cui mi sto questo errore e come ottenerlo. Non è Text
solo un sinonimo di [Char]
?
No, 'Text' è un tipo completamente diverso. 'String' è un sinonimo di' [Char] ', comunque. – melpomene
Sfortunatamente, Haskell ha diversi tipi in conflitto per stringhe di caratteri. Nel tuo caso, aggiungendo '{- # LANGUAGE OverloadedStrings # -}' come la prima riga del tuo programma dovrebbe farla compilare. – stholzm
Grazie, ha funzionato davvero. Per favore, rispondi a questo commento, e accetterò. –