无法将预期类型'[a]'与实际类型'a'匹配

时间:2017-05-13 17:09:19

标签: haskell

为什么这会给我错误?

insertAt :: Int -> a -> [a] -> [a]
insertAt n x xs = x1 ++ x ++ x2
    where (x1,x2) = splitAt n xs

1 个答案:

答案 0 :(得分:3)

您正在混合列表和列表元素 - 您必须将元素打包在单例列表中

insertAt :: Int -> a -> [a] -> [a]
insertAt n x xs = x1 ++ [x] ++ x2
    where (x1,x2) = splitAt n xs