Heterogenous list implemented with GADT

Hello fellow beginners (and the rest of you, too), I was reading http://en.wikibooks.org/wiki/Haskell/GADT and I really liked the simple eval example. But I reached the end and was confused by the following definition of a heterogenous list: data TG2 where MkTG2 :: Show b => [b] -> TG2 I had thought a heterogeneous list was something like [ 5 , 'Z', 3.14, False ] How can the TG2 definition support the list I've given above? Or am I just wrong about what a heterogeneous list is? Thanks, -- kov This email and any attachments may contain information which is confidential and/or privileged. The information is intended exclusively for the addressee and the views expressed may not be official policy, but the personal views of the originator. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents is prohibited. If you have received this email and any file transmitted with it in error, please notify the sender by telephone or return email immediately and delete the material from your computer. Internet communications are not secure and Lab49 is not responsible for their abuse by third parties, nor for any alteration or corruption in transmission, nor for any damage or loss caused by any virus or other defect. Lab49 accepts no liability or responsibility arising out of or in any way connected to this email.

On Thursday 30 September 2010 21:08:01, Ken Overton wrote:
Hello fellow beginners (and the rest of you, too), I was reading http://en.wikibooks.org/wiki/Haskell/GADT and I really liked the simple eval example. But I reached the end and was confused by the following definition of a heterogenous list:
data TG2 where MkTG2 :: Show b => [b] -> TG2
I had thought a heterogeneous list was something like
[ 5 , 'Z', 3.14, False ]
How can the TG2 definition support the list I've given above?
It can't.
Or am I just wrong about what a heterogeneous list is?
I rather think the wikibook author expressed (her|him)self incorrectly. What TG2 does is wrap a list of (henceforth) unknown type (as long as the type has a Show instance, and that Show instance is made available by pattern matching). To achieve something like your example, you'd need data TG3 where MkTG3 :: Show a => a -> TG3 xs :: [TG3] xs = [MkTG3 5, MkTG3 'Z', MkTG3 3.14, MkTG3 False]
Thanks,
-- kov

On Sep 30, 2010, at 4:00 PM, Daniel Fischer wrote:
What TG2 does is wrap a list of (henceforth) unknown type (as long as the type has a Show instance, and that Show instance is made available by pattern matching).
Thanks, that sheds some light on the usefulness of GADTs in general for me.
To achieve something like your example, you'd need
data TG3 where MkTG3 :: Show a => a -> TG3
xs :: [TG3] xs = [MkTG3 5, MkTG3 'Z', MkTG3 3.14, MkTG3 False]
Much clearer, thanks a lot. --kov This email and any attachments may contain information which is confidential and/or privileged. The information is intended exclusively for the addressee and the views expressed may not be official policy, but the personal views of the originator. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents is prohibited. If you have received this email and any file transmitted with it in error, please notify the sender by telephone or return email immediately and delete the material from your computer. Internet communications are not secure and Lab49 is not responsible for their abuse by third parties, nor for any alteration or corruption in transmission, nor for any damage or loss caused by any virus or other defect. Lab49 accepts no liability or responsibility arising out of or in any way connected to this email.
participants (2)
-
Daniel Fischer
-
Ken Overton