[Haskell-beginners] Type signature question
Brandon Allbery
allbery.b at gmail.com
Tue Jul 23 16:46:48 CEST 2013
On Tue, Jul 23, 2013 at 10:33 AM, Louis-Guillaume Gagnon <
louis.guillaume.gagnon at gmail.com> wrote:
> 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.
>
It shows up because of `firstHalf == secondHalf`; you used (==), this
requires an Eq constraint so that the type-appropriate implementation of
(==) is available.
--
brandon s allbery kf8nh sine nomine associates
allbery.b at gmail.com ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130723/f8aa25d8/attachment.htm>
More information about the Beginners
mailing list