3 ms·
> I’ve often wondered why relational databases don’t have sum types. It seems unlikely that relational databases would make the effort to add sum types whilst
by tome 5y ago
> I’ve often wondered why relational databases don’t have sum types.
It seems unlikely that relational databases would make the effort to add sum types whilst mainstream imperative languages don't have sum types. In turn that is probably because of a mistaken belief that subclassing was a sufficient means to achieve the same end. All is not lost, however. It's easy to simulate sum types using a field for the tag and multiple fields for the payload.
The syntax for that in raw SQL doesn't look nice but in a higher level query DSL it can look lovely!
https://hackage.haskell.org/package/opaleye-0.7.1.0/docs/Opaleye-MaybeFields.html https://hackage.haskell.org/package/opaleye-0.7.1.0/docs/Opa...
https://hackage.haskell.org/package/rel8-1.0.0.0/docs/Rel8.html#g:11 https://hackage.haskell.org/package/rel8-1.0.0.0/docs/Rel8.h...
(Disclaimer: I'm the author of Opaleye)