4 ms·
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 trait
by noelwelsh 12y ago
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-fast-error-handling.html http://underscore.io/blog/posts/2015/02/23/designing-fail-fa...). 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.