[Haskell-beginners] Type signature question

Erik Price erikprice at gmail.com
Tue Jul 23 16:59:01 CEST 2013


My reply is a bit ambiguous, so to clarify: the parameter doesn't have to
be of the Eq type class, because the parameter is a list. But the list's
elements have to be of the Eq type class.

e


On Tue, Jul 23, 2013 at 10:57 AM, Erik Price <erikprice at gmail.com> wrote:

> It's saying that you can't pass parameters to this function unless they
> are of the Eq type class, because somewhere in the body of the function is
> code that expects parameters to be of this type class.
>
> e
>
>
> On Tue, Jul 23, 2013 at 10:33 AM, Louis-Guillaume Gagnon <
> louis.guillaume.gagnon at gmail.com> wrote:
>
>> Hello beginners,
>>
>> I'm working on the second set of exercises in ch.03 of Real World Haskell
>>
>> I wrote a palindromize function (:: [a] -> [a]) which transforms a
>> list in a palindrome (eg. [1,2,3] -> [1,2,3,3,2,1]) .
>>
>> I wrote a isPalindrome function which checks whether a given list is
>> such a palindrome.
>> it reads:
>> isPalindrome xs
>>      | odd (length xs)              = False
>>      | firstHalf == secondHalf =True
>>      | otherwise                       = False
>>      where half              = div (length xs) 2
>>                 firstHalf       = take half xs
>>                 secondHalf = reverse (drop half xs)
>>
>> I would expect the type signature to be:
>> isPalindrome :: [a] -> Bool
>>
>> but ghci gives me
>> is Eq a => [a] -> Bool
>>
>> and I don't undestand why the "Eq a =>" shows up.
>>
>> many thanks,
>>
>> glg
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130723/a2c672d4/attachment.htm>


More information about the Beginners mailing list