[Haskell-cafe] Why is the no tuple syntax for sum types

Scott Turner 2haskell at pkturner.org
Mon Aug 3 11:44:39 UTC 2015


On 2015-07-31 18:44, Phil Ruffwind wrote:
> For sum types you need a way to construct them and pattern match them.
> Without a way to _name_ them, it would probably look like this:
>
>     showError :: (Result | Error3 | Error8) -> String
>     showError (result ||)   = "no error"
>     showError (| error3 |)  = "error3: " ++ show error3
>     showError (|| error8 |) = "error8: " ++ show error8
>
> It's not the most readable code, so I'd generally avoid using it for
> anything greater than 3 (same applies to tuples).
This approach misses the essence of sum type tuples, which is
positional. It needs to be something like
    showError :: (Result | Error3 | Error) -> String
    showError = case of
                    result -> "no error"
                    | error3 -> "error3: " ++ show error3
                    | error3 -> "error8: " ++ show error8

This is just to illustrate the overall structure that's needed. I don't
think think the above "|" syntax would ever fit into Haskell, because it
would be confused with pattern guards.


More information about the Haskell-Cafe mailing list