2016-11-06 48 views
0
insert :: Eq(a) => a -> a -> [a] -> [a] 
insert m n [] = [] 
insert m n (x1:x1:xs) | m==x = n : x : insert m n xs 
    | otherwise = x : insert m n xs 

insert函数已经工作。我需要interspace的帮助。目标是我希望两个元素在给出的两个其他元素之间写入一个元素。该程序是用Haskell编写的。 interspace函数应该在两个其他给定元素之间写入给定元素(如果它们在列表中)。Haskell中的空间函数

interspace :: Eq(a) => a -> a -> a->[a] -> [a] 
interspace m n q[] = [] 
interspace m n q (x:xs)| m==x && q==(head xs) = n: x : insert m n (headxs)++interspace m n q (xs) 
    | otherwise = x : interspace m n q xs 
+0

尝试matcing'。 –

+0

你是什么意思,你可以给我新的代码? –

+0

这个问题仍然很糟糕。您应该编辑第一个副本以改进它。 – dfeuer

回答

0

你的程序应该像对`(X1:X2:XS)

interspace m n q [] = [] 
interspace m n q (x1:x2:xs) | .... = .... 
interspace m n q (x:xs) = x : interspace m n q xs