3 ms·
> To make sum types work, you NEED to support embed relations inside relations If that is the case, sum types would be in violation of first normal form.
by goto11 5y ago
> To make sum types work, you NEED to support embed relations inside relations
If that is the case, sum types would be in violation of first normal form.
- mamcx 5y agoEven considering that normal forms are tools... Sum types, how them are stored and how they are used is not the same ie: How are sum types represented in languages like Rust/oCalm? that is tangential as how we experience them. So, support to embed relations is the step to provide the storage and partially, help in the query, but from the POV of the user them are "normal sum types". But with that, you get the ability to store relations, that is usefull as-is :)
- emmelaich 5y agoOddly enough, 1nf is differently defined depending on which person or database you're asking/using. Is it . just to be rectangular? . values are atomic? (and what does that mean) . no such thing as nulls? good luck with that . no duplicate rows (good luck with enforcing that in intermediate tables)
- goto11 5y agoE.F.Codd defines first normal form as eliminating nested relations (in "A Relational Model of Data for Large Shared Data Banks" which introduces the relational model). "Atomic" in this context just means any value which is not a relation. A relation by definition cannot have duplicate rows, since relations are sets. If "rectangular" means that all rows in a table have the same columns (attributes), this also follows from the definition of relations. So these constraints have to be fulfilled before we can even talk about normalization, since normalization operates on relations. (Nulls are its own can of worms, but dosn't really have anything to do with 1NF.) Codd introduces 1NF because he realized supporting nested relations would complicate the model and query language for no benefit. It would need special operators for navigate in and out or nested relations, e.g. if you wanted to join tables nested at different levels in other tables. You would need something like XPath on top of SQL. But you can express exactly the same information using foreign keys between tables and keep the language simpler. The sum-types suggestion shows the problem. If we have sum types as values, presumably they would be composed of other types, right? So sum types could contain other sum types, arbitrary deep. Since you surely would want to query these individual values, you would need operators in SQL to navigate down into sum types. You would need facilities to index and apply constraints, again arbitrary deep down the structure. So the database model and query language gets significantly more complex for dubious benefit.
- mamcx 5y ago> So the database model and query language gets significantly more complex for dubious benefit. Sum types are definitively not a "dubious benefit". Neither nesting relations (that are not that different to join them and will provide better semantics that create a LOT of null columns to flat them). Will complicate matters and requiere extensions? Sure. But is clear that, today in this century, exist a lot of use-cases where people are resorting to pseudo-nosql (json embedding, to name one of the biggest anti-patterns), and that create more inconsistent features, extensions, weird extra syntax, etc. that anyway are required for it (and could have been cleaner under this idea). With this, we can get the same benefits and much more. P.D. Not against have a very simple core and try to model stuff that way, but the major point of a model, like relational, is support how to MODEL. And we need to model nested thing, and we need to model variants and get rids of nulls and all that. So, sometimes, you need to add complexity + 1 so you get complications - 10.