Last active
August 29, 2015 14:03
-
-
Save Chris-Gillis/b0fba486ecaec9917d04 to your computer and use it in GitHub Desktop.
Palindrome in Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
palindrome :: Eq a => [a] -> Bool | |
palindrome [] = True | |
palindrome (x:[]) = True | |
palindrome (x:_:y:[]) = x == y | |
palindrome xs | head xs /= last xs = False | |
| head xs == last xs = palindrome $ stripFirstAndLast xs | |
where stripFirstAndLast ys = tail $ reverse $ tail $ reverse ys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment