为什么这会给我错误?
insertAt :: Int -> a -> [a] -> [a]
insertAt n x xs = x1 ++ x ++ x2
where (x1,x2) = splitAt n xs
答案 0 :(得分:3)
您正在混合列表和列表元素 - 您必须将元素打包在单例列表中
insertAt :: Int -> a -> [a] -> [a]
insertAt n x xs = x1 ++ [x] ++ x2
where (x1,x2) = splitAt n xs