fumieval / extensible

Extensible records, variants, structs, effects, tangles
BSD 3-Clause "New" or "Revised" License
128 stars 20 forks source link

Accumulation of sums reverses element order #35

Open andriusstank opened 1 year ago

andriusstank commented 1 year ago

The type of accumulation operator taken by haccum (it's ... -> g x -> h x -> h x) suggests right fold will be performed, while in fact haccum performs left fold.

This mismatch is evident with hpartition function - element order gets reversed:

embedInt :: Int -> '[Int] :/ Identity
embedInt x  = EmbedAt membership (Identity x)

items :: ['[Int] :/ Identity]
items = embedInt <$> [1,2,3]

y :: '[Int] :& Compose [] Identity
y = hpartition id items

-- >>> y
-- Compose [Identity 3,Identity 2,Identity 1] <: nil