Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find a Type Class's ancestors?

Tags:

haskell

In the following picture we see that RealFloat is an instance of Floating, which in turn is an instance of Fractional etc...

For any type class in Haskell how can we find all the "parents" ?

enter image description here

like image 439
McBear Holden Avatar asked Oct 09 '14 12:10

McBear Holden


1 Answers

Just use the ghci interpreter. To demonstrate your example:

λ> :i RealFloat
class (RealFrac a, Floating a) => RealFloat a where
  floatRadix :: a -> Integer
  floatDigits :: a -> Int
  .....
instance Floating Float -- Defined in `GHC.Float'
instance Floating Double -- Defined in `GHC.Float'
λ> :i Floating
class Fractional a => Floating a where
  pi :: a
  exp :: a -> a
  .....

From the above example, you can see how RealFloat is related to RealFrac and Floating and how Floating is related to Fractional.

like image 141
Sibi Avatar answered Oct 30 '22 12:10

Sibi