The deriving keyword can be used to make a new type into an instance of other built-in classes
Enumwithout the need for defining any of the methods. For example, the
Booltype can be declared as:
data Bool = False | True
deriving (Eq, Ord, Show, Read)
It is as if we are stating that the new data type
Boolcan have two values (two nullary constructors
False) and it should also be made an instance of the classes
Read, but we let the compiler write the actual code for us using the default definitions. Note that for the
Ordclass, the default ordering will be the order in which the constructors are defined – in this case,
Falseand is, therefore "greater than"
False. With this definition, we can use methods of all the class instances included with the type
ghci> True == True
ghci> False < True
ghci> show True
ghci> read "False"