
Hello. I'm wondering what " (Eq a) =>" part in the code below does.. I couldn't figure it myself.. Thanks in advance :) isPalindrome :: (Eq a) => [a] -> Bool isPalindrome xs = xs == (reverse xs)

"(Eq a) =>" means that the type a in the function's signature must be an instance of the Eq typeclass. Instances of Eq are types where equality is defined, Eq's member functions are (==) and (/=), equality and inequality tests. Le samedi 18 février 2012 20:16:05, bahadýr altan a écrit :
Hello. I'm wondering what " (Eq a) =>" part in the code below does.. I couldn't figure it myself.. Thanks in advance :) isPalindrome :: (Eq a) => [a] -> Bool isPalindrome xs = xs == (reverse xs)

Hello. I'm wondering what " (Eq a) =>" part in the code below does.. I couldn't figure it myself.. Thanks in advance :)
isPalindrome :: (Eq a) => [a] -> Bool isPalindrome xs = xs == (reverse xs)
It's a type constraint. In this case, it's saying that, rather than isPalindrome working only for a particular type, instead it works for any type "a" which has an implementation of the Eq class, where "a" is the type of the items in the passed list. Technically, it's telling the compiler to
On Sat, Feb 18, 2012 at 15:16, bahadýr altan
participants (3)
-
ARJANEN Loïc Jean David
-
bahadýr altan
-
Brandon Allbery