我有一个字符串列表,我想在下面的代码列表的末尾添加一个字符串,但我收到类型匹配错误列表:哈斯克尔 - 如何将字符串到字符串
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