O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required