Working out of RWH, Chapter 3 question 5 requests I create a function to test for the existence of a paldindrome.
I wrote this, but it doesn't work
pCheck :: (Eq a) => [a] -> Bool;
pCheck a = take n a == ( take n $ reverse a )
where n = floor ( length a / 2 )
I get this error when I try to run it:
No instance for (RealFrac Int)
arising from a use of `floor' at len.hs:13:11-32
Possible fix: add an instance declaration for (RealFrac Int)
In the expression: floor (length a / 2)
In the definition of `n': n = floor (length a / 2)
In the definition of `pCheck':
pCheck a = take n a == (take n $ reverse a)
where
n = floor (length a / 2)
I'm confused what am I doing wrong? I know a paldindrome could just as well be tested with a == reverse a
, but now I want to find the error in my way.
UPDATE: one of the errors with the code was fixed by a suggestion by Justice, the question has been updated to reflect the remaining problem