Sum types in Julia

There is a semantic difference between sum types and union types, but it is subtle. The difference is that Sum{Foo, Bar} contains information about whether it is a left object of type Foo, or a right object of type Bar. This difference is important when the intersection of Foo and Bar is non-empty.

For instance, in Haskell:

GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
Prelude> let foo 0 = Left (); foo n = Right ()
Prelude> let bar (Left _) = "left"; bar (Right _) = "right"
Prelude> foo 0
Left ()
Prelude> foo 1
Right ()
Prelude> bar (foo 0)
"left"
Prelude> bar (foo 1)
"right"

whereas a union type loses the left/right information.

From Wikipedia,

In set theory the equivalent of a sum type is a disjoint union, a set which elements are pairs consisting of a tag (equivalent to a constructor) and an object of a type corresponding to the tag (equivalent to the constructor arguments).