@@ -290,11 +290,11 @@ ggname gfromColumns = case algebraSing @algebra of
290type GGAggregate :: K.Algebra -> (K.Context -> Exp (Type -> Type)) -> Type -> Type
290type GGAggregate :: K.Algebra -> (K.Context -> Exp (Type -> Type)) -> Type -> Type
291type family GGAggregate algebra rep r where
291type family GGAggregate algebra rep r where
292 GGAggregate 'K.Product rep r =
292 GGAggregate 'K.Product rep r =
293− GConstruct TUnreify (Eval (rep (Reify Expr)))
294− (GConstruct (Compose Aggregate TUnreify) (Eval (rep (Reify Expr))) r -> r)
293+ GConstruct (Compose Aggregate TUnreify) (Eval (rep (Reify Expr))) r ->
294+ GConstruct TUnreify (Eval (rep (Reify Expr))) r
295 GGAggregate 'K.Sum rep r =
295 GGAggregate 'K.Sum rep r =
296− GBuildADT TUnreify (Eval (rep (Reify Expr)))
297− (GBuildADT (Compose Aggregate TUnreify) (Eval (rep (Reify Expr))) r -> r)
296+ GBuildADT (Compose Aggregate TUnreify) (Eval (rep (Reify Expr))) r ->
297+ GBuildADT TUnreify (Eval (rep (Reify Expr))) r
300ggaggregate :: forall algebra rep a. GGConstructable algebra rep
300ggaggregate :: forall algebra rep a. GGConstructable algebra rep
@@ -302,7 +302,7 @@ ggaggregate :: forall algebra rep a. GGConstructable algebra rep
302 -> (a -> Eval (GGColumns algebra TColumns (Eval (rep (Reify Result)))) (Col Expr))
302 -> (a -> Eval (GGColumns algebra TColumns (Eval (rep (Reify Result)))) (Col Expr))
303 -> GGAggregate algebra rep (Aggregate a) -> a -> Aggregate a
303 -> GGAggregate algebra rep (Aggregate a) -> a -> Aggregate a
304ggaggregate gfromColumns gtoColumns agg es = case algebraSing @algebra of
304ggaggregate gfromColumns gtoColumns agg es = case algebraSing @algebra of
305− SProduct -> f $
305+ SProduct -> flip f exprs $
307 ( gfromColumns
307 ( gfromColumns
308 . hunreify
308 . hunreify
@@ -317,17 +317,10 @@ ggaggregate gfromColumns gtoColumns agg es = case algebraSing @algebra of
318 gtraverse @TUnreify @(Eval (rep (Reify Expr))) @_ @Aggregate (MaybeApply . Left)
318 gtraverse @TUnreify @(Eval (rep (Reify Expr))) @_ @Aggregate (MaybeApply . Left)
323− @(Eval (rep (Reify Expr)))
324− @(GConstruct (Compose Aggregate TUnreify) (Eval (rep (Reify Expr))) (Aggregate a) -> Aggregate a)
321+ gindex @TUnreify @(Eval (rep (Reify Expr))) @(Aggregate a) .
328− @(Compose Aggregate TUnreify)
323+ gtabulate @(Compose Aggregate TUnreify) @(Eval (rep (Reify Expr))) @(Aggregate a)
329− @(Eval (rep (Reify Expr)))
332 gdeconstruct
325 gdeconstruct
333 @(TTable (Reify Expr))
326 @(TTable (Reify Expr))
@@ -338,8 +331,7 @@ ggaggregate gfromColumns gtoColumns agg es = case algebraSing @algebra of
338 (\(_ :: proxy x) -> unreify @_ @x Refl . fromColumns) $
331 (\(_ :: proxy x) -> unreify @_ @x Refl . fromColumns) $
340 gtoColumns es
333 gtoColumns es
342− SSum -> f exprs $
334+ SSum -> flip f exprs $
344 (\tag' ->
336 (\tag' ->
345 gfromColumns .
337 gfromColumns .
@@ -357,17 +349,10 @@ ggaggregate gfromColumns gtoColumns agg es = case algebraSing @algebra of
357 (groupByExpr tag) .
349 (groupByExpr tag) .
358 gftraverse @TUnreify @(Eval (rep (Reify Expr))) @_ @Aggregate (MaybeApply . Left)
350 gftraverse @TUnreify @(Eval (rep (Reify Expr))) @_ @Aggregate (MaybeApply . Left)
363− @(Eval (rep (Reify Expr)))
364− @(GBuildADT (Compose Aggregate TUnreify) (Eval (rep (Reify Expr))) (Aggregate a) -> Aggregate a)
353+ gfindex @TUnreify @(Eval (rep (Reify Expr))) @(Aggregate a) .
368− @(Compose Aggregate TUnreify)
355+ gftabulate @(Compose Aggregate TUnreify) @(Eval (rep (Reify Expr))) @(Aggregate a)
369− @(Eval (rep (Reify Expr)))
371 (HType (Reify (DB tag)), exprs) =
356 (HType (Reify (DB tag)), exprs) =
372 gunbuildADT
357 gunbuildADT
373 @(TTable (Reify Expr))
358 @(TTable (Reify Expr))
@@ -386,11 +371,11 @@ ggaggregate gfromColumns gtoColumns agg es = case algebraSing @algebra of
386type GGAggregate' :: K.Algebra -> (K.Context -> Exp (Type -> Type)) -> Type -> Type
371type GGAggregate' :: K.Algebra -> (K.Context -> Exp (Type -> Type)) -> Type -> Type
387type family GGAggregate' algebra rep r where
372type family GGAggregate' algebra rep r where
388 GGAggregate' 'K.Product rep r =
373 GGAggregate' 'K.Product rep r =
389− GConstruct TUnreify (Eval (rep (Reify Expr)))
374+ GConstruct TUnreify (Eval (rep (Reify Aggregate))) r ->
390− (GConstruct TUnreify (Eval (rep (Reify Aggregate))) r -> r)
375+ GConstruct TUnreify (Eval (rep (Reify Expr))) r
391 GGAggregate' 'K.Sum rep r =
376 GGAggregate' 'K.Sum rep r =
392− GBuildADT TUnreify (Eval (rep (Reify Expr)))
377+ GBuildADT TUnreify (Eval (rep (Reify Aggregate))) r ->
393− (GBuildADT TUnreify (Eval (rep (Reify Aggregate))) r -> r)
378+ GBuildADT TUnreify (Eval (rep (Reify Expr))) r
396ggaggregate' :: forall algebra rep exprs agg. GGConstructable algebra rep
381ggaggregate' :: forall algebra rep exprs agg. GGConstructable algebra rep
@@ -398,7 +383,7 @@ ggaggregate' :: forall algebra rep exprs agg. GGConstructable algebra rep
398 -> (exprs -> Eval (GGColumns algebra TColumns (Eval (rep (Reify Result)))) (Col Expr))
383 -> (exprs -> Eval (GGColumns algebra TColumns (Eval (rep (Reify Result)))) (Col Expr))
399 -> GGAggregate' algebra rep agg -> exprs -> agg
384 -> GGAggregate' algebra rep agg -> exprs -> agg
400ggaggregate' gfromColumns gtoColumns agg es = case algebraSing @algebra of
385ggaggregate' gfromColumns gtoColumns agg es = case algebraSing @algebra of
401− SProduct -> f $
386+ SProduct -> flip f exprs $
402 gfromColumns .
387 gfromColumns .
403 hunreify .
388 hunreify .
404 gconstruct
389 gconstruct
@@ -410,16 +395,9 @@ ggaggregate' gfromColumns gtoColumns agg es = case algebraSing @algebra of
410 (\(_ :: proxy x) -> toColumns . reify @_ @x Refl)
395 (\(_ :: proxy x) -> toColumns . reify @_ @x Refl)
415− @(Eval (rep (Reify Expr)))
398+ gindex @TUnreify @(Eval (rep (Reify Expr))) @agg .
416− @(GConstruct TUnreify (Eval (rep (Reify Aggregate))) agg -> agg)
421− @(Eval (rep (Reify Aggregate)))
400+ gtabulate @TUnreify @(Eval (rep (Reify Aggregate))) @agg
424 gdeconstruct
402 gdeconstruct
425 @(TTable (Reify Expr))
403 @(TTable (Reify Expr))
@@ -430,7 +408,7 @@ ggaggregate' gfromColumns gtoColumns agg es = case algebraSing @algebra of
430 (\(_ :: proxy x) -> unreify @_ @x Refl . fromColumns) $
408 (\(_ :: proxy x) -> unreify @_ @x Refl . fromColumns) $
432 gtoColumns es
410 gtoColumns es
433− SSum -> f exprs $
411+ SSum -> flip f exprs $
434 gfromColumns .
412 gfromColumns .
435 hunreify .
413 hunreify .
436 gbuildADT
414 gbuildADT
@@ -444,17 +422,10 @@ ggaggregate' gfromColumns gtoColumns agg es = case algebraSing @algebra of
444 Reify $ Aggregation $ runTag nullity (tag ==. litExpr tag') <$> a)
422 Reify $ Aggregation $ runTag nullity (tag ==. litExpr tag') <$> a)
445 (HType (Reify (Aggregation (groupByExpr tag))))
423 (HType (Reify (Aggregation (groupByExpr tag))))
450− @(Eval (rep (Reify Expr)))
426+ gfindex @TUnreify @(Eval (rep (Reify Expr))) @agg .
451− @(GBuildADT TUnreify (Eval (rep (Reify Aggregate))) agg -> agg)
456− @(Eval (rep (Reify Aggregate)))
428+ gftabulate @TUnreify @(Eval (rep (Reify Aggregate))) @agg
458 (HType (Reify (DB tag)), exprs) =
429 (HType (Reify (DB tag)), exprs) =
459 gunbuildADT
430 gunbuildADT
460 @(TTable (Reify Expr))
431 @(TTable (Reify Expr))