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 []
I like the existential quantification example. Nice stuff!
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:
Will print:
Pretty cool!