Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I get the "class Num a where" instead of the "class (Eq a, Show a) => Num a"?

Tags:

haskell

ghci

I learn Haskell. I send the command into ghci: :info Num.

ghci> :info Num
class Num a where
(+) :: a -> a -> a
(*) :: a -> a -> a
(-) :: a -> a -> a
negate :: a -> a
abs :: a -> a
signum :: a -> a
fromInteger :: Integer -> a
-- Defined in `GHC.Num'
instance Num Integer -- Defined in `GHC.Num'
instance Num Int -- Defined in `GHC.Num'
instance Num Float -- Defined in `GHC.Float'
instance Num Double -- Defined in `GHC.Float'

I expected to see something like that: class (Eq a, Show a) => Num a, but I see class Num a where. I was surprised... Ok, I open the Hoogle and try to find info for the Num class type. I got this result. I see the class (Eq a, Show a) => Num a in the first record of searching result. But when I open the sources I see:

-- | Basic numeric class.
--
-- Minimal complete definition: all except 'negate' or @(-)@
class  Num a  where

Why I get the class Num a where instead of the class (Eq a, Show a) => Num a?

like image 525
Andrey Bushman Avatar asked Dec 19 '14 07:12

Andrey Bushman


2 Answers

Hackage showing class (Eq a, Show a) => Num a is probably a bug, but there really is no reason for Num a to require Eq a and Show a.

like image 187
Shoe Avatar answered Oct 04 '22 19:10

Shoe


I think the search index of Hoogle is pretty old.

You can see that Eq and Show superclass is removed from Num in these commits of ghc.

https://github.com/ghc/ghc/commit/0a40540e79223f38ee851c66eb377db9a1756e4b https://github.com/ghc/ghc/commit/817c4e19a4248b80f0af764d12721b1284b39e5a

So I consider that this is the reason of the inconsistency between search result of Hoogle and actual link to Hackage.

like image 21
ymonad Avatar answered Oct 04 '22 17:10

ymonad