我有一个函数,旨在将列表中的字符串组合在一起,在每个字符串之间添加一个分隔符,并使用foldl输出单个字符串。这是我的功能,以及该功能的某些预期行为-它无法正常工作,我不确定为什么。
-- | `sepconcat sep [s1,...,sn]` returns `s1 ++ sep ++ s2 ++ ... ++ sep ++ sn`
--
-- >>> sepconcat "---" []
-- ""
--
-- >>> sepconcat "," ["foo","bar","baz"]
-- "foo,bar,baz"
--
-- >>> sepconcat "#" ["a","b","c","d","e"]
-- "a#b#c#d#e"
sepconcat :: String -> [String] -> String
sepconcat sep [] = ""
sepconcat sep (x:xs) = foldLeft f base l
where
f a x = a ++ sep ++ x
base = ""
l = xs