In this recipe, we will create a list of heterogeneous types which are instances of the type class Show. We will use an ExistentialQuantification extension to show the list. We will use StandaloneDeriving extension to derive a type class instance.
Working with existentially quantified type
How to do it...
- Create a new project working-with-existentials with a simple stack template:
stack new working-with-existentials simple
- Open src/Main.hs. We will be adding our source here.
- Enable the existential support, and define the Main module. Also add StandaloneDeriving extension.
{-# LANGUAGE ExistentialQuantification, StandaloneDeriving #-} module Main where
- Define an existential type:
data...