Reputation: 498
I am new to Haskell, and trying to implement the code from here to replace strings using a map. I am getting an error message during compilation that says
* Expecting one more argument to `StringMap'
Expected a type, but `StringMap' has kind `* -> *'
* In the type signature:
stringMapReplace :: (Show stringMap) => StringMap -> String -> String
I have tried searching, but the only answer I can find for the error is that I'm not clarifying what type StringMap
is. However, I thought that is what Show stringMap
was doing.
import Data.Map
import Data.Strings
type StringMap stringMap = [(String, String)]
myStringMap =
[
("org1", "rep1"),
("org2", "rep2")
]
stringMapReplace :: (Show stringMap) => StringMap -> String -> String
stringMapReplace [] s = s
stringMapReplace (m:ms) s = strReplace ms (replace (fst m) (snd m) s)
main :: IO ()
main = do
putStrLn "Enter some text:"
putStrLn =<< stringMapReplace myStringMap <$> toUpper getLine
Note: strReplace
comes from Data.Strings
I don't know if there is anything else wrong with the code, as the compiler is only giving the error above right now. If you notice anything else right off, please feel free to mention (or leave it for me to debug later as practice).
Upvotes: 0
Views: 84
Reputation: 21811
You defined the type synonym StringMap
to take an (unused) type parameter stringMap
. Type synonyms, as opposed to newtype
, data
, and GADT declarations, must always be fully applied. Thus every occurrence of StringMap
must be have a parameter supplied, like forall a . StringMap a
, StringMap Int
, etc. In the signature of stringMapReplace
, you do not give StringMap
a parameter, hence the error.
Two options:
StringMap
to type StringMap = [(String, String)]
, because it doesn't need a parameter.Give StringMap
a parameter in the signature of stringMapReplace
. What parameter, you ask? Any one, because it is ignored. For example, the following should work:
stringMapReplace :: StringMap String -> String -> String
Upvotes: 4