Last active
August 29, 2015 14:08
-
-
Save vertexcite/69f30ef3f900db73dd15 to your computer and use it in GitHub Desktop.
Heterogeneous List in Haskell (simple version)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ExistentialQuantification #-} | |
-- This is adapted from http://en.wikibooks.org/wiki/Haskell/Existentially_quantified_types | |
-- See also https://www.haskell.org/haskellwiki/Heterogenous_collections#Existential_types | |
module HeterogeneousList where | |
data ShowBox = forall s. Show s => SB s | |
heteroList :: [ShowBox] | |
heteroList = [SB (), SB (5::Integer), SB True] | |
instance Show ShowBox where | |
show (SB s) = show s -- (*) see the comment in the text below | |
f :: [ShowBox] -> IO () | |
f = mapM_ print | |
main :: IO () | |
main = f heteroList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment