But I find this pretty inefficient (duplication of the list and double of needed comparisons).
isPalindrome xs =
isPalindrome' 0 (length xs)
where isPalindrome' i j =
if i == j -- line 43
then True
else
if (xs !! i) == (xs !! (j-1))
then isPalindrome' (i+1) (j-1)
else False
But, when trying to load this in ghci it throws the following error:
xxx.hs:43:12: parse error (possibly incorrect indentation)
Failed, modules loaded: none.
(Line 43 is marked in the code)
I seems that the definition of isPalindrome' must be in one line. So, this works as expected:
isPalindrome xs =
isPalindrome' 0 (length xs)
where isPalindrome' i j = if i == j then True else if (xs !! i) == (xs !! (j-1)) then isPalindrome' (i+1) (j-1) else False
Is there any way to make the local definition of isPalindrome' more readable?
Any help in understanding this would be appreciated
Thanks in advance,
M;