

Zero-Overhead Union Types in Scala - noelwelsh
http://japgolly.blogspot.com/2015/02/zero-overhead-recursive-adt-coproducts.html

======
noelwelsh
I like this solution to union types. It uses sealed traits in a way I hadn't
thought of before -- essentially inverted the usual strategy for using sealed
traits to establish a sum type. Other strategies I've seen for union types
involve implicit evidence, which this approach does not need.

I just wrote a blog post about error handling which shows where union types
can be really useful ([http://underscore.io/blog/posts/2015/02/23/designing-
fail-fa...](http://underscore.io/blog/posts/2015/02/23/designing-fail-fast-
error-handling.html)). I didn't really go into the use of union types in that
post because the pre-existing techniques I knew of were all rather involved.
This is simple enough that I think it's viable to use even in relatively
unsophisticated code bases.

------
mjt0229
This is really neat. As a professional Scala hacker who's played a bit with
SML/OCaml, I always seem to find problems that would be best solved using
discriminated unions like this, but I've never loved the traditional Scala
idioms for achieving that sort of thing. I'm interested in Shapeless, but my
coworkers are suspicious and I'm too inexpert in it to really argue strongly
for it. This looks like something useful that I can implement when a union
type is really what I need, without having to get Shapeless in the door.

