A type has a superclass if its definition contains a type constraint.
Num does not have any superclasses
class Num a where
Fractional has Num as a superclass
class Num a => Fractional a where
A subclass can use the methods defined in its superclass(es).
A superclass cannot use the methods defined in its subclass(es).
Int is not a class
data Int
And therefore, cannot be a subclass nor a superclass.
Superclass
Fractional is a type class that requires types to already have an instance of the Num type class. Therefore Num is a superclass of Fractional.
Therefore, + & other functions from the Num typeclass can be used with Fractional
The methods of Num are
(+) :: a -> a -> a
(-) :: a -> a -> a
(*) :: a -> a -> a
negate :: a -> a
abs :: a -> a
signum :: a -> a
fromInteger :: Integer -> a
The methods of Fractional are
(/) :: a -> a -> a
recip :: a -> a
fromRational :: Rational -> a
However, a value of type Fractional can use all the methods of Num because the definition for Fractional says that all values that are Fractional must be Num.
class Num a => Fractional a where
Subclass
Again:
Fractional is a type class that requires types to already have an instance of the Num type class.
Brief
A type has a superclass if its definition contains a type constraint.
Num
does not have any superclassesFractional
hasNum
as a superclassInt
is not a classAnd therefore, cannot be a subclass nor a superclass.
Superclass
Fractional
is a type class that requires types to already have an instance of theNum
type class. ThereforeNum
is a superclass ofFractional
.+
& other functions from theNum
typeclass can be used withFractional
The methods of
Num
are(+) :: a -> a -> a
(-) :: a -> a -> a
(*) :: a -> a -> a
negate :: a -> a
abs :: a -> a
signum :: a -> a
fromInteger :: Integer -> a
The methods of
Fractional
are(/) :: a -> a -> a
recip :: a -> a
fromRational :: Rational -> a
However, a value of type
Fractional
can use all the methods ofNum
because the definition forFractional
says that all values that areFractional
must beNum
.Subclass
Again:
Fractional
is a type class that requires types to already have an instance of theNum
type class.Therefore
Num
is a subclass ofFractional
.