Haskell, 26 bytes
(++"[]").((++":").show=<<)
Explanation:
In non-pointfree notation and using concatMap
instead of =<<
, this becomes
f s = concatMap(\c-> show c ++ ":")s ++ "[]"
Given a string s
, we map each char c
to a string "'c':"
using the show
function which returns a string representation of most Haskell types. Those strings are concatenated and a final []
is appended.
Although not requested by the challenge, this answer even works with proper escaping, because show
takes care of it: f "'"
yields "'\\'':[]"
.