<div class="gmail_quote">On Tue, Jun 21, 2011 at 1:36 PM, Matthew Steele <span dir="ltr">&lt;<a href="mailto:mdsteele@alum.mit.edu">mdsteele@alum.mit.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">On Jun 21, 2011, at 4:02 PM, Malcolm Wallace wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 21 Jun 2011, at 20:53, Elliot Stern wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
A tuple is basically an anonymous product type.  It&#39;s convenient to not have to spend the time making a named product type, because product types are so obviously useful.<br>
<br>
Is there any reason why Haskell doesn&#39;t have anonymous sum types?  If there isn&#39;t some theoretical problem, is there any practical reason why they haven&#39;t been implemented?<br>
</blockquote>
<br>
The Either type is the nearest Haskell comes to having anonymous sum types.<br>
<br>
If you are bothered because Either has a name and constructors, it does not take long before you realise that (,) has a name and a constructor too.<br>
</blockquote>
<br></div>
Yes, Either is to sum types what (,) is to product types.  The difference is that there is no &quot;anonymous&quot; sum type equivalent to (,,) and (,,,) and (,,,,) and so on, which I think is what the original question is getting at.  Indeed, I sometimes wish I could write something like (straw-man syntax):<br>


<br>
  foo :: (Int | Bool | String | Double) -&gt; Int<br>
  foo x =<br>
    case x of<br>
      1stOf4 i -&gt; i + 7<br>
      2ndOf4 b -&gt; if b then 1 else 0<br>
      3rdOf4 s -&gt; length s<br>
      4thOf4 d -&gt; floor d<br>
  bar :: Int<br>
  bar = foo (2ndOf4 True)<br>
<br>
and have that work for any size of sum type.  But I can&#39;t.<br></blockquote><div><br>The syntax is truly awful, but this doesn&#39;t seem that far from<br><br>foo :: Either Int (Either Bool (Either String Double)) -&gt; Int<br>

foo (Left e) = e + 7<br>foo (Right (Left e )) = if e then 1 else 0<br>foo (Right (Right (Left e))) = length e<br>foo (Right (Right (Right e))) = floor e<br>foo . Right . Left $ True <br><br>Mike<br><br></div></div>