# Modeling union types using sum types

It is trivial to model sum types using only union types and product types: simply add a discriminant. $A + B \cong (0 \times A) \cup (1 \times B)$.

What I am wondering is whether or not there is a concise, practical representation for union types using sum types and product types.

• I don't think this question is sufficiently precise to be a research-level question, because it's important to define what exactly you mean by a "representation" (let alone a "concise, practical" one). I suspect you might be looking for an implementation along the lines of Joshua Dunfield's "Elaborating Intersection and Union Types" (cs.cmu.edu/~joshuad/papers/intcomp). – Noam Zeilberger Dec 25 '16 at 12:25
• On the other hand, there is also a simple counterpart to your equation, which basically says that a union is the "image of a sum along the codiagonal map". You could have a look at some notes I wrote (noamz.org/oplss16/refinements-notes.pdf) which discuss such equations (see p.70, Equations 3.10 and 3.13) and explains how to interpret them in a very general categorical setting. – Noam Zeilberger Dec 25 '16 at 12:27
• I was rather thinking the OP should define what he means by union. Types are not sets, so there's no such thing as union of types, at least not until someone defines it. In fact, the question is ill-posed since it's usng set-theoretic terminology but it speaks about types. That just doesn't make a lot of sense. I am downvoting until this gets fixed. – Andrej Bauer Dec 26 '16 at 20:52
• Andrej: saying that "there's no such thing as union of types" is dogmatic and inappropriate, because there is a substantial literature on union types (e.g., check out the bibliography in the Dunfield paper I linked). Don't be mislead by the set-theoretic terminology (which is standard though): the proper way of thinking about intersection and union types is in fibrational terms ("union type" is essentially just another name for "fibered coproduct"). – Noam Zeilberger Dec 26 '16 at 22:54
• @MartinBerger I don't know enough about session types to answer that, but when I have more time I'll try to think about it and send you an email. – Noam Zeilberger Dec 28 '16 at 14:15