<br><br><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">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):</div>
<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><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) -> Int</div><div> foo =</div><div> \ i -> i + 7 ???</div>
<div> \ b -> if b then 1 else 0 ???</div><div> \ s -> length s ???</div><div> \ d -> floor d</div><div> </div><div><br></div></div>