
On 01-Dec-2000, Eric Allen Wohlstadter
Is there a way to make a list that contains multiple types? If not, why, and isn't this a serious restriction? I would like to be able to say:
map show ['a',5]
Since both Char and Num derive Show it seems like a reasonable thing to do.
You can't do it in standard Haskell, but with ghc extensions you can
achieve the same effect. For example, the following program
data Showable = forall a . Show a => Showable a
instance Show Showable where
show (Showable x) = show x
example = map show [Showable 'a', Showable 5]
main = print example
produces the output
["'a'","5"]
See http://www.haskell.org/ghc/docs/latest/set/existential-quantification.html
for more details.
--
Fergus Henderson