<div class="gmail_quote">On Tue, Jun 21, 2011 at 1:36 PM, Matthew Steele <span dir="ltr"><<a href="mailto:mdsteele@alum.mit.edu">mdsteele@alum.mit.edu</a>></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'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't have anonymous sum types? If there isn't some theoretical problem, is there any practical reason why they haven'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 "anonymous" 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) -> Int<br>
foo x =<br>
case x of<br>
1stOf4 i -> i + 7<br>
2ndOf4 b -> if b then 1 else 0<br>
3rdOf4 s -> length s<br>
4thOf4 d -> 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't.<br></blockquote><div><br>The syntax is truly awful, but this doesn't seem that far from<br><br>foo :: Either Int (Either Bool (Either String Double)) -> 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>