klequis / zz-haskell-notebook

Notes from learning Haskell
1 stars 0 forks source link

Superclass & Subclass #52

Open klequis opened 2 years ago

klequis commented 2 years ago

Brief

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

Int is not a class

data Int

And therefore, cannot be a subclass nor a superclass.

Superclass

The methods of Num are

The methods of Fractional are

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:

Therefore Num is a subclass of Fractional.