Hi everyone,<br><br>I believe I have come to the conclusion that what I would like to do is impossible, but I would like to have that confirmed. I would basically like to be able to have a heterogeneous list without boxing everything in a data type. Below is the sample code, with the code I would like to use commented out. I'm I missing something, or does Haskell simply not support what I am trying for?<br>
<br><span style="font-family: courier new,monospace;">{-# LANGUAGE ExistentialQuantification #-}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">data Foo = Foo String</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">class IFoo a where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> toFoo :: a -> Foo</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">instance IFoo Foo where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> toFoo = id</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">data A = A String</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance IFoo A where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> toFoo (A a) = Foo a</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">data B = B Int</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">instance IFoo B where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> toFoo (B b) = Foo $ show b</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">data FooBox = forall t. IFoo t => FooBox t</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance IFoo FooBox where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> toFoo (FooBox f) = toFoo f</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">myPrint :: IFoo t => [(String, t)] -> IO ()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">myPrint = mapM_ myPrint'</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">myPrint' :: IFoo t => (String, t) -> IO ()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">myPrint' (key, value) =</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> let (Foo foo) = toFoo value</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> in putStrLn $ key ++ ": " ++ foo</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{- What I'd like to do:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">main = myPrint</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> [ ("one", Foo "1")</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> , ("two", A "2")</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ]</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">-}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">main = myPrint</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> [ ("one", FooBox $ Foo "1")</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> , ("two", FooBox $ A "2")</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ]</span><br><br>----<br><br>Thanks<br style="font-family: courier new,monospace;"><br>