haskellari / postgresql-simple

Mid-level client library for accessing PostgreSQL from Haskell
Other
88 stars 46 forks source link

Export GFromRow and GToRow for use as constraints #84

Open carymrobbins opened 2 years ago

carymrobbins commented 2 years ago

This is useful for generalizing over things which can have their FromRow and ToRow instances derived. Specifically, this would enable libraries like generic-override to be able to interop with postgresql-simple's generic machinery.


Without this change, given the following code -

instance (Generic (Override a xs)) => ToRow (Override a xs)

We'll get the following compiler error -

Could not deduce (Database.PostgreSQL.Simple.ToRow.GToRow
                          (Data.Override.Internal.OverrideRep
                             Data.Override.Internal.EmptyInspect xs (Rep a)))
        arising from a use of ‘Database.PostgreSQL.Simple.ToRow.$dmtoRow’

This can be easily fixed by adding the GToRow constraint -

instance (Generic (Override a xs), GToRow (Override a xs)) => ToRow (Override a xs)

However, this can't be done unless the constraint itself is exported.

carymrobbins commented 2 years ago

Looks like the checks failed only on AppVeyor, which looks to be a linker error.

@phadej - Are you the one to approve/merge this? Would be good to know if this change would be accepted or if there is some alternative you'd like instead.