假设:
mangle :: String -> String
我想做类似的事情:
mangle xs = head xs -- works if you change typesig to [a] -> a
但:
mangle xs = tail xs ++ head xs -- won't work at all!
想在列表的末尾追加列表的第一个字符,删除第一个字符。
答案 0 :(得分:6)
非常直接的解决方案可能如下所示:
mangle :: String -> String
mangle [] = []
mangle (x:xs) = xs ++ [x]