Haskell获取列表的第一个Char并附加到该列表的末尾

时间:2017-11-18 09:25:24

标签: haskell tail

假设:

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!

想在列表的末尾追加列表的第一个字符,删除第一个字符。

1 个答案:

答案 0 :(得分:6)

非常直接的解决方案可能如下所示:

mangle :: String -> String
mangle [] = []
mangle (x:xs) = xs ++ [x]