On Tue, Jun 21, 2011 at 1:36 PM, Matthew Steele <mdste...@alum.mit.edu>wrote:

> 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):
>
>  foo :: (Int | Bool | String | Double) -> Int
>  foo x =
>    case x of
>      1stOf4 i -> i + 7
>      2ndOf4 b -> if b then 1 else 0
>      3rdOf4 s -> length s
>      4thOf4 d -> floor d
>  bar :: Int
>  bar = foo (2ndOf4 True)
>
> and have that work for any size of sum type.  But I can't.
>
>
Haskell operators are pretty flexible. You can get something really close
without much effort. Consider:

 import Data.Either
 type (:|:) a b = Either a b
 (???) = either

 foo :: (Int :|: Bool :|: String :|: Double) -> Int
 foo =
    \ i  -> i + 7  ???
    \ b -> if b then 1 else 0 ???
    \ s -> length s ???
    \ d -> floor d
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to