0
votes

I have this code:

censName :: String -> String
censName [] = []
censName xs = unwords(censWords(words xs))

censWords :: [String] -> [String]
censWords [] = []
censWords (x:xs) = if isUpper(head x) then replace(tail x) else censWords xs 

replace :: String -> String
replace [] = []
replace (x:xs) = '*':replace xs

and the error says:

Couldn't match type ‘Char’ with ‘[Char]’
  Expected type: [String]
    Actual type: String

and my questions is: why!? i mean, in replace(tail x) x is a String, so why it expects [String]?

i couldn't find nothing to fit to my problem on similar problems posted here.

1

1 Answers

2
votes
censWords :: [String] -> [String]
                      -- ^^^^^^^^ expected
censWords (x:xs) = if .. then replace(tail x) else ..
                           -- ^^^^^^^^^^^^^^^ actual value

The returned value is a single string, but a list of strings was expected.

The issue is not the call to replace, but the fact that it returns a value of the wrong type than the expected one.