<br><br><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">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):</div>

<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><br></blockquote><div><br></div><div>Haskell operators are pretty flexible. You can get something really close without much effort. Consider:</div><div><br>
</div><div> import Data.Either</div><div> type (:|:) a b = Either a b</div><div> (???) = either</div><div><br></div><div> foo :: (Int :|: Bool :|: String :|: Double) -&gt; Int</div><div> foo =</div><div>    \ i  -&gt; i + 7  ???</div>
<div>    \ b -&gt; if b then 1 else 0 ???</div><div>    \ s -&gt; length s ???</div><div>    \ d -&gt; floor d</div><div> </div><div><br></div></div>