2016-11-06 46 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