[Haskell-beginners] Type signature question
Matthew Lefavor
mclefavor at gmail.com
Tue Jul 23 16:44:12 CEST 2013
On Tue, Jul 23, 2013 at 10:33 AM, Louis-Guillaume Gagnon <
louis.guillaume.gagnon at gmail.com> wrote:
> 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
>
"Eq a" is the "Type class" of "a". It means that "a" is a type that
supports the checking of equality.
Other type classes include: "Show" (types that are printable), and "Ord"
(types that are orderable).
Cheers,
MCL
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130723/16c6787c/attachment.htm>
More information about the Beginners
mailing list