Open karamaan opened 10 years ago
Just to be clear, the reason that this is undesirable is that it is a violation of referential transparency. ("Referential transparency" here is with respect to the database, not with respect to Haskell, of course!) An expression's value should be unchanged when you replace a subexpression with its value. For example agesOfFamilies
might evaluate to
Family | Age |
---|---|
Smith | 75 |
Jones | 85 |
Replacing agesOfFamilies
in the definition justAgesOfFamilies
with its value (i.e. this table) would lead to a result of
Age | |
---|---|
75 | |
85 |
Since HaskellDB gives us
Age | |
---|---|
160 |
this is a violation of referential transparency.
The semantics of HaskellDB's aggregation operators is very unclear. Let me propose the following example to demonstrate my confusion. It concerns a table whose rows represent people. A person has a family and an age.
I might want to calculate the total age of everyone in a family. This I do with
agesOfFamilies
. It returns a query whose rows (ostensibly) pair the family with the total age of everyone in that family.I can test it with
showSql
thus:which is exactly what I wanted. What happens if I want to project just the age column from this query?
It seems that
justAgesOfFamilies
should return a single-column query with one row for each family containing their total age, i.e. the result of the queryagesOfFamilies
without thefamily
column. However, what I get is completely differentThis kind of behaviour seems to be an enormous impediment to composability of queries in HaskellDB.