Skip to content

Instantly share code, notes, and snippets.

@Chris-Gillis
Last active August 29, 2015 14:03
Show Gist options
  • Save Chris-Gillis/b0fba486ecaec9917d04 to your computer and use it in GitHub Desktop.
Save Chris-Gillis/b0fba486ecaec9917d04 to your computer and use it in GitHub Desktop.
Palindrome in Haskell
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