Deriving Eq1 via Generically1 doesn't work and never did
Summary
There's following instance for Generically1
(perhaps originally taken from the generic-data
package)
(Generic1 f, Eq1 (Rep1 f)) => Eq1 (Generically1 f)
The constraint Eq1 (Rep1 f)
is not satisfiable and never was because auxiliary Generics types like M1
(aka D1
in the error below) don't have Eq1
instance.
NB The same applies to Ord1
. Also there's no Show1
instance for Generically1
.
Steps to reproduce
Take following program
#!/usr/bin/env cabal
{- cabal:
build-depends:
, base
default-language:
Haskell2010
ghc-options:
-main-is Test
-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE TypeApplications #-}
module Test (main) where
import Data.Functor.Classes
import GHC.Generics (Generic1, Generically1(..))
data I a = I [a] (Maybe a)
deriving stock (Eq, Ord, Show, Generic1)
deriving (Eq1) via (Generically1 I)
main :: IO ()
main = do
let x = I @Int [1, 2] (Just 3)
y = I @Int [] Nothing
putStrLn $ show $ eq1 x y
pure ()
And run it under GHC:
$ cabal run ./Test.hs
Created semaphore called cabal_semaphore_f with 32 slots.
/tmp/Test.hs:22:13: error: [GHC-39999]
• No instance for ‘Eq1
(GHC.Generics.D1
(GHC.Generics.MetaData
"I" "Test" "fake-package-0-inplace-script-Test.hs" False)
(GHC.Generics.C1
(GHC.Generics.MetaCons "I" GHC.Generics.PrefixI False)
(GHC.Generics.S1
(GHC.Generics.MetaSel
Nothing
GHC.Generics.NoSourceUnpackedness
GHC.Generics.NoSourceStrictness
GHC.Generics.DecidedLazy)
(GHC.Generics.Rec1 [])
GHC.Generics.:*: GHC.Generics.S1
(GHC.Generics.MetaSel
Nothing
GHC.Generics.NoSourceUnpackedness
GHC.Generics.NoSourceStrictness
GHC.Generics.DecidedLazy)
(GHC.Generics.Rec1 Maybe))))’
arising from the 'deriving' clause of a data type declaration
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
• When deriving the instance for (Eq1 I)
|
22 | deriving (Eq1) via (Generically1 I)
| ^^^
Expected behavior
Print False
, generally derive the Eq1
instance without errors.
Probably either the Eq1
instance for Generically1
should be removed since it doesn't work and never did or *1 instances for M1
and the rest should be added.
Environment
- GHC version used: 9.8, 9.6, 9.4, 9.2, 8.10
Optional:
- Operating System: Linux
- System Architecture: x86_64