Hi all,<br><br>I&#39;m trying to write a function (I&#39;ll call it `vtuple&#39; for lack of a better name)<br>that returns a function that itself returns multiple arguments in the form of a<br>tuple. For example:<br><br>&gt; {-# LANGUAGE FlexibleInstances #-}<br>

&gt; {-# LANGUAGE FunctionalDependencies #-}<br>&gt; {-# LANGUAGE MultiParamTypeClasses #-}<br><br>&gt; f :: Int -&gt; IO ()<br>&gt; f = undefined<br><br>&gt; g :: Int -&gt; Int -&gt; IO ()<br>&gt; g = undefined<br><br>&gt; h :: Int -&gt; Int -&gt; Int -&gt; IO ()<br>

&gt; h = undefined<br><br>vtuple f :: IO (Int -&gt; (Int, ()))<br>vtuple g :: IO (Int -&gt; Int -&gt; (Int, (Int, ())))<br><br>I&#39;ve tried to type vtuple using a type class; my current effort is something<br>like:<br>
<br>
&gt; class VTuple ia ir a r | r -&gt; a, a -&gt; ia where<br>&gt;   vtuple :: (ia -&gt; ir) -&gt; IO (a -&gt; r)<br><br>&gt; instance VTuple Int (IO ()) Int (Int, ()) where<br>&gt; --vtuple :: (Int -&gt; IO ()) -&gt; IO (Int -&gt; (Int, ()))<br>

&gt;   vtuple = undefined<br><br>&gt; instance VTuple ia ir a r<br>&gt;       =&gt; VTuple Int (ia -&gt; ir) Int (a -&gt; (Int, r)) where<br><br>&gt; --vtuple :: (Int -&gt; ia -&gt; ir) -&gt; IO (Int -&gt; a -&gt; (Int, r))<br>

&gt;   vtuple = undefined<br><br>But this is problematic, since arrows creep in:<br><br>For one argument (fine):<br>  vtuple :: (Int -&gt; IO ()) -&gt; IO (Int -&gt; (Int, ()))<br><br>&gt; vf :: IO (Int -&gt; (Int, ()))<br>

&gt; vf = vtuple f<br><br>For two arguments (also fine):<br>  vtuple  :: (Int -&gt; Int -&gt; IO ())<br>          -&gt; IO (Int -&gt; Int -&gt; (Int, (Int, ())))<br><br>&gt; vg :: IO (Int -&gt; Int -&gt; (Int, (Int, ())))<br>

&gt; vg = vtuple g<br><br>For three (noooo!):<br>  vtuple  :: (Int -&gt; Int -&gt; IO ())<br>          -&gt; IO (Int -&gt; Int -&gt; (Int, (Int -&gt; (Int32, (Int32, ())))))<br><br>And so on. I&#39;ve thought about it and it seems impossible to solve this problem<br>

-- you keep needing to ``split&#39;&#39; the function type one arrow further on. Is<br>this a job for Template Haskell or is there a solution I&#39;m missing here? Note<br>that I&#39;d also like to use types other than Int, but I don&#39;t think this is the<br>

primary complication here (touch wood).<br><br>Any help much appreciated, thanks,<br>Will<br>