How to find ancestors of class type?

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

For any type of class in Haskell, how can we find all the β€œparents”?

enter image description here

+4
source share
1 answer

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
  .....

In the above example, you can see how it RealFloatis related to RealFracand Floatingand how it Floatingis related to Fractional.

+6
source

All Articles