Haskell take first Char of list and append at end of that list

Viewed 3260

Given:

mangle :: String -> String

and I want to do something like:

mangle xs = head xs -- works if you change typesig to [a] -> a

but:

mangle xs = tail xs ++ head xs -- won't work at all!

Would like to append the first Char of a list at the end of that list, cutting that first Char.

1 Answers

A very straight-forward solution could look like this:

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