0

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

1 Answer 1

4

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:

  1. Change StringMap to type StringMap = [(String, String)], because it doesn't need a parameter.
  2. 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
    
Sign up to request clarification or add additional context in comments.

1 Comment

@chi Thanks. Fixed now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.