#!/usr/bin/runghc module Recursion06IsPalindrome where import Data.List as L import Data.Vector as V isPalindromeRev :: (Eq a) => [a] -> Bool isPalindromeRev xs = xs == L.reverse xs isPalindromeRec :: (Eq a, Show a) => Vector a -> Bool isPalindromeRec xs = V.length xs == 1 || let lastPos = (V.length xs - 1) firstElem = xs V.! 0 lastElem = xs V.! lastPos in firstElem == lastElem && isPalindromeRec (V.slice 1 (lastPos - 1) xs) main :: IO () main = do print (isPalindromeRev "a") print (isPalindromeRev "racecar") print (isPalindromeRev "racecat") print (isPalindromeRec (V.fromList "a")) print (isPalindromeRec (V.fromList "racecar")) print (isPalindromeRec (V.fromList "racecat"))