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
嘗試matcing'。 –
你是什麼意思,你可以給我新的代碼? –
這個問題仍然很糟糕。您應該編輯第一個副本以改進它。 – dfeuer