【发布时间】:2021-11-13 00:40:09
【问题描述】:
我的 if then else 语句出现解析错误,我不明白为什么。我已经检查了函数,据我所知,他们都得到了他们需要的参数,所以我不明白为什么会这样。我对 haskell 非常陌生,因此我们将不胜感激。
replace :: [(Int,Int)] -> String -> String
replace xs ys = if translate (manipulator (fst (convert xs)) (snd (convert xs)) ys) /= ""
then take (fst (convert xs)) ys ++ (manipulator (fst (convert xs)) (snd (convert xs)) ys) ++ drop (snd (convert xs)) ys
else take (fst (convert xs)) ys ++ stjerner (snd (convert xs) - fst (convert xs)) ++ drop (snd (convert (xs)) ys
--get parse error here, see picture.
stjerner :: Int -> String
stjerner 0 = ""
stjerner int | int > 0 = "*" ++ stjerner (int -1)
manipulator:: Int -> Int -> String -> String
manipulator low high xs = take high (drop low xs)
convert :: [a] -> a
convert [a] = a
【问题讨论】:
-
看起来您在上面的行中有一个未闭合的括号。这真的不是非常惯用的 Haskell,使用这么多嵌套括号应该很少见。考虑改用
$运算符。 -
您使用
convert xs的次数很多。您应该使用let (f,s) = convert xs in ...之类的东西,然后直接使用f,s。注意convertcrashs是xs的长度不是1。这看起来很可能是错误的。 -
this 是您的代码应该如何编写的。看看那里是否更容易发现错误。
标签: haskell parse-error