Reputation: 21
I am trying to write a function that takes in a string and makes a palindrome out of it.
For example, ace
becomes aceeca
.
Upvotes: 1
Views: 2060
Reputation: 574
palindrome [] = []
palindrome (x:xs) = append (x:(palindrome xs)) x
where append (x:xs) y = x:(append xs y)
append [] y = [y]
Upvotes: 0
Reputation: 1204
Pretty easy, just concatenate the reversed string onto itself.
palindrome s = s ++ reverse s
++ is the list concatenation function.
Let me point you toward Real World Haskell. It's a good book for learning the language if you're just getting started.
Upvotes: 7