Description
I recently reproduced all 3 of the beam tutorials in a slightly different context, and while doing so, I found some strange results. I'll record them below; it's not totally obvious to me if these are a result of a problem in the tutorial or a problem in beam itself (or indeed a misunderstanding on my part).
allUsersAndTotals
The tutorial gives two versions for the query for allUsersAndTotals
. The text mentions that the second one could perform significantly better than the first; from this I gather that both queries are intended to be equivalent. However, the first query returns
(betty,Just 16500)
(james,Just 0)
(sam,Just 0)
which is incorrect, as it has james
total at zero. The second query does give the correct result:
(james,Just 27000)
(betty,Just 16500)
(sam,Just 0)
shippingInformationByUser
For this query the tutorial gives three variants. For the first query, the tutorial correctly points out that it computes an incorrect result:
(betty,0,1)
(james,2,0)
(sam,1,0)
This is incorrect, because sam
placed no orders at all, and so can't have any unshipped orders either. The tutorial then goes on to fix the query, but the result of that new fixed query is
(betty,1,1)
(james,2,1)
(sam,1,1)
Now the results are off for all users! Finally, the third variant of the query (with explicit subselect_
) also returns this same, incorrect (I think), result.
NoMonomorphismRestriction
Finally, a minor comment. In tutorial2, it is important that in
let james = User "[email protected]" "James" "Smith" "b4cc344d25a2efe540adbf2678e2304c"
betty = User "[email protected]" "Betty" "Jones" "82b054bd83ffad9b6cf8bdb98ce3cc2f"
sam = User "[email protected]" "Sam" "Taylor" "332532dcfaa1cbf61e2a266bd723612c"
a polymorphic type is inferred for these values (that is, forall f. IsString (Columnar f Text) => UserT f
): this is important because these values are sometimes used in the tutorial at UserT Identity
(for example, in insertValues
), and sometimes at UserT (QExpr Sqlite s)
, for example when using pk james
etc. in the definition of the addresses
(rather than val_ (pk james)
). This requires the NoMonomorphismRestriction
to be enabled. Might be worth pointing that out to avoid some confusion.