dreixel / generic-deriving

BSD 3-Clause "New" or "Revised" License
44 stars 32 forks source link

Should `GFoldable' (Rec1 f)` be constrained by `Foldable` #76

Closed Icelandjack closed 3 years ago

Icelandjack commented 3 years ago

I tried making a Foldable instance of Generically1 so that I could derive

data Queue a = Queue [a] (Reverse [] a)
  deriving stock Generically1
  deriving Foldable via Generically1 Queue

and it seemed like

instance GFoldable f => GFoldable' (Rec1 f) where
  gfoldMap' f (Rec1 a) = gfoldMap f a

needed to be changed to Foldable

instance Foldable f => GFoldable' (Rec1 f) where
  gfoldMap' f (Rec1 a) = foldMap f a
RyanGlScott commented 3 years ago

This is by design, as the GFoldable class is meant to be a pedagogical example that is separate from the Foldable class in base. The README talks about this:

It is worth emphasizing that these modules are primarly intended for educational purposes. Many of the classes in these modules resemble other commonly used classes—for example, GShow from Generics.Deriving.Show resembles Show from base—but in general, the classes that generic-deriving defines are not drop-in replacements. Moreover, the generic defaults that generic-deriving provide often make simplifying assumptions that may violate expectations of how these classes might work elsewhere. For example, the generic default for GShow does not behave exactly like deriving Show would.

If you are seeking GHC.Generics-based defaults for type classes in base, consider using the generic-data library.

As such, I'm going to close this as being outside the scope of generic-deriving.