1. 3
  1.  

  2. 1

    I like the existential quantification example. Nice stuff!

    1. 2

      Another common example is a heterogenous list, where the contents have different types but they all support a common operation. For example, let’s say we wanted log values of different types:

      data Showable = forall a. Show a => Showable a
      
      instance Show Showable where
        show (Showable a) = show a
      
      log :: Show a => a -> [Showable] -> [Showable]
      log a ss = Showable a : ss
      
      main :: IO ()
      main = print . log "three" . log True $ log 1 []
      

      Will print:

      ["three",True,1]
      

      Pretty cool!