我有一個字符串列表,我想在下面的代碼列表的末尾添加一個字符串,但我收到類型匹配錯誤列表:哈斯克爾 - 如何將字符串到字符串
eliminateImpl :: [String] -> String -> [String]
eliminateImpl [] _ = []
eliminateImpl (p:ps) r = if (contains (p:ps) "Impl")
then if (p == "Impl")
then "Not " ++r++" Or "++ps -- TRYING TO CONCATENATE HERE
else let r = r++p
in eliminateImpl ps r
else (p:ps)
contains :: [String] -> String -> Bool
contains [_] [] = True
contains [] _ = False
contains (p:ps) c = if p == c
then True
else contains ps c
代碼的實際功能是函數eleminateImpl採用一階邏輯表達式,例如:「eliminationImpl [」Q(y)「,」Impl「,」P(x)「] []」和它應去除含義並修改表達式,以便輸出爲:「exceptImpl [」Not「,」Q(y)「,」Or「,」P(x)「]
我試過r ++ p和r:p但兩者都不起作用,這是錯誤:
Couldn't match type ‘Char’ with ‘[Char]’
Expected type: [String] Actual type: [Char] In the first argument of ‘(++)’, namely ‘"Not "’ In the expression: "Not " ++ r ++ " Or " ++ ps In the expression: if (p == "Impl") then "Not " ++ r ++ " Or " ++ ps else let r = r ++ p in eliminateImpl ps r
有沒有另一種方法呢?
之後的字符串列表應該是什麼樣的? – 2014-11-23 17:27:17
你能解釋一下你想做什麼嗎?我似乎無法理解你寫的內容。 – user2008934 2014-11-23 17:30:24
@SebastianRedl函數應該得到一個一階邏輯表達式,例如:「eliminateImpl [」Q(y)「,」Impl「,」P(x)「] []」,函數應該刪除蘊含並修改表達式,以便輸出爲:「exceptImpl [」Not「,」Q(y)「,」Or「,」P(x)「]」 – SalmaFG 2014-11-23 17:30:39