List types

Fergus Henderson
Sat, 2 Dec 2000 13:28:19 +1100

On 01-Dec-2000, Eric Allen Wohlstadter <> wrote:
> 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


for more details.

Fergus Henderson <>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <>  |     -- the last words of T. S. Garp.