Sunday 1 May 2016

Haskell: type classes extension


Haskell supports class extension. For example type class Ord inherits all of the operations from Eq, but in addition it has a set of comparison operations, minimum and maximum functions.

class  (Eq a) => Ord a  where
  (<), (<=), (>=), (>)  :: a -> a -> Bool
  max, min              :: a -> a -> a


We used to call Eq as super class of Ord. Ord is the sub class of Eq. Any type which is an instance of Ord must also be an instance of Eq.


Previous                                                 Next                                                 Home

No comments:

Post a Comment