agrafix / superrecord

Haskell: Supercharged anonymous records
BSD 3-Clause "New" or "Revised" License
83 stars 16 forks source link

Semigroup instance inverted #33

Open Profpatsch opened 2 years ago

Profpatsch commented 2 years ago
ghci> sconcat (First 'a' :| [First 'b'])
First {getFirst = 'a'}
ghci> sconcat ((Rec.rnil & Rec.rcons (#foo Rec.:= First 'a')) :| [(Rec.rnil & Rec.rcons (#foo Rec.:= First 'b'))])
[("foo","First {getFirst = 'b'}")]

I’d expect both to return the same result, since all I did was to wrap the First in a #foo field …

Profpatsch commented 1 year ago

Oh, I think I get it: The values are not even looked at by the instance:

(Semigroup (Rec lts), UnsafeRecBuild lts lts (ConstC Monoid :: Symbol -> TYPE LiftedRep -> Constraint)) => Monoid (Rec lts)

lts here is completely opaque.

But that also means <> is equivalent of always throwing away the left record, no? Cause there is nothing to be done with the values.

Profpatsch commented 1 year ago

Ah no, I missed the constraint ConstC Monoid, of course the values are looked at.

Better example:

> (rcons (#foo := "a") rnil) <> (rcons (#foo := "b") rnil)
[("foo","\"ba\"")]