September 2017
Beginner to intermediate
396 pages
9h 46m
English
In this recipe, we have primarily used the ExistentialQuantification extension. Note how we have defined the data type, Display:
data Display = forall a . Show a => Display a
An important thing to note here is that the type variable a does not appear on the left-hand side. It only appears on right-hand side expressions. It also appears with a construct forall a . Show a. It is a way of embedding information about the type class that is embedded inside the data type. In this case, it tells us that Display is defined for all a which are instances of Show. In this way, the data constructor Display a embeds a value of type a. But the only information that is available to us is about the type class Show. This means that we can ...
Read now
Unlock full access