Skip to content

Change instances for Product and Sum to have (NFData (f a), NFData (g a)` constraints #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
phadej opened this issue Dec 27, 2022 · 7 comments

Comments

@phadej
Copy link
Contributor

phadej commented Dec 27, 2022

To be aligned with change Eq1 and Ord1 instances in base-4.18 (GHC-8.6). The #88 could done at the same time. The change in base is described in haskell/core-libraries-committee#10, AFAICT the rationale applies to deepseq as well.

cc @Icelandjack and @Ericson2314

@mixphix
Copy link
Collaborator

mixphix commented Jan 21, 2023

I made only the following changes to Control.DeepSeq and tested them with ghc-9.6.0.20230111, the first alpha version for ghc-9.6:

#if MIN_VERSION_base(4,18,0)
class (forall a. NFData (f a)) => NFData1 f where
#else
class NFData1 f where
#endif

#if MIN_VERSION_base(4,18,0)
class (forall a. NFData1 (p a)) => NFData2 p where
#else
class NFData2 p where
#endif

This was the output:

GHCi, version 9.6.0.20230111: https://www.haskell.org/ghc/  :? for help

<no location info>: warning:
    -XGeneralizedNewtypeDeriving is not allowed in Safe Haskell; ignoring -XGeneralizedNewtypeDeriving
[1 of 1] Compiling Control.DeepSeq  ( Control/DeepSeq.hs, interpreted )

Control/DeepSeq.hs:468:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 Identity’
    |
468 | instance NFData1 Identity where
    |          ^^^^^^^^^^^^^^^^

Control/DeepSeq.hs:496:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 Ratio’
    |
496 | instance NFData1 Ratio where
    |          ^^^^^^^^^^^^^

Control/DeepSeq.hs:500:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData1 f, NFData1 g)
        bound by the instance declaration at Control/DeepSeq.hs:500:10-56
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 (Compose f g)’
    |
500 | instance (NFData1 f, NFData1 g) => NFData1 (Compose f g) where
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Control/DeepSeq.hs:508:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData1 f, NFData1 g)
        bound by the instance declaration at Control/DeepSeq.hs:508:10-60
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 (Functor.Sum f g)’
    |
508 | instance (NFData1 f, NFData1 g) => NFData1 (Functor.Sum f g) where
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Control/DeepSeq.hs:517:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData1 f, NFData1 g)
        bound by the instance declaration at Control/DeepSeq.hs:517:10-64
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 (Functor.Product f g)’
    |
517 | instance (NFData1 f, NFData1 g) => NFData1 (Functor.Product f g) where
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Control/DeepSeq.hs:534:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 Maybe’
    |
534 | instance NFData1 Maybe where
    |          ^^^^^^^^^^^^^

Control/DeepSeq.hs:540:10: error: [GHC-39999]
    • Could not deduce ‘NFData a1’
        arising from the superclasses of an instance declaration
      from the context: NFData a
        bound by the instance declaration at Control/DeepSeq.hs:540:10-41
      Possible fix:
        add (NFData a1) to the context of a quantified context
    • In the instance declaration for ‘NFData1 (Either a)’
    |
540 | instance (NFData a) => NFData1 (Either a) where liftRnf = liftRnf2 rnf
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Control/DeepSeq.hs:542:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData2 Either’
    |
542 | instance NFData2 Either where
    |          ^^^^^^^^^^^^^^

Control/DeepSeq.hs:552:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 []’
    |
552 | instance NFData1 [] where
    |          ^^^^^^^^^^

Control/DeepSeq.hs:561:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 ZipList’
    |
561 | instance NFData1 ZipList where
    |          ^^^^^^^^^^^^^^^

Control/DeepSeq.hs:571:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData2 Const’
    |
571 | instance NFData2 Const where
    |          ^^^^^^^^^^^^^

Control/DeepSeq.hs:580:10: error: [GHC-39999]
    • Could not deduce ‘NFData a1’
        arising from the superclasses of an instance declaration
      from the context: NFData a
        bound by the instance declaration at Control/DeepSeq.hs:580:10-40
      Possible fix:
        add (NFData a1) to the context of a quantified context
    • In the instance declaration for ‘NFData1 (Array a)’
    |
580 | instance (NFData a) => NFData1 (Array a) where
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Control/DeepSeq.hs:584:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData2 Array’
    |
584 | instance NFData2 Array where
    |          ^^^^^^^^^^^^^

Control/DeepSeq.hs:590:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 Down’
    |
590 | instance NFData1 Down where
    |          ^^^^^^^^^^^^

Control/DeepSeq.hs:596:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 Dual’
    |
596 | instance NFData1 Dual where
    |          ^^^^^^^^^^^^

Control/DeepSeq.hs:602:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 Mon.First’
    |
602 | instance NFData1 Mon.First  where
    |          ^^^^^^^^^^^^^^^^^

Control/DeepSeq.hs:608:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 Mon.Last’
    |
608 | instance NFData1 Mon.Last  where
    |          ^^^^^^^^^^^^^^^^

Control/DeepSeq.hs:620:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 Sum’
    |
620 | instance NFData1 Sum where
    |          ^^^^^^^^^^^

Control/DeepSeq.hs:626:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 Product’
    |
626 | instance NFData1 Product where
    |          ^^^^^^^^^^^^^^^

Control/DeepSeq.hs:830:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 NonEmpty’
    |
830 | instance NFData1 NonEmpty where
    |          ^^^^^^^^^^^^^^^^

Control/DeepSeq.hs:836:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 Min’
    |
836 | instance NFData1 Min where
    |          ^^^^^^^^^^^

Control/DeepSeq.hs:842:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 Max’
    |
842 | instance NFData1 Max where
    |          ^^^^^^^^^^^

Control/DeepSeq.hs:848:10: error: [GHC-39999]
    • Could not deduce ‘NFData a1’
        arising from the superclasses of an instance declaration
      from the context: NFData a
        bound by the instance declaration at Control/DeepSeq.hs:848:10-38
      Possible fix:
        add (NFData a1) to the context of a quantified context
    • In the instance declaration for ‘NFData1 (Arg a)’
    |
848 | instance (NFData a) => NFData1 (Arg a) where liftRnf = liftRnf2 rnf
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Control/DeepSeq.hs:850:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData2 Arg’
    |
850 | instance NFData2 Arg where
    |          ^^^^^^^^^^^

Control/DeepSeq.hs:856:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 Semi.First’
    |
856 | instance NFData1 Semi.First where
    |          ^^^^^^^^^^^^^^^^^^

Control/DeepSeq.hs:862:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 Semi.Last’
    |
862 | instance NFData1 Semi.Last where
    |          ^^^^^^^^^^^^^^^^^

Control/DeepSeq.hs:868:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 WrappedMonoid’
    |
868 | instance NFData1 WrappedMonoid where
    |          ^^^^^^^^^^^^^^^^^^^^^

Control/DeepSeq.hs:906:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 Solo’
    |
906 | instance NFData1 Solo where
    |          ^^^^^^^^^^^^

Control/DeepSeq.hs:917:10: error: [GHC-39999]
    • Could not deduce ‘NFData a1’
        arising from the superclasses of an instance declaration
      from the context: NFData a
        bound by the instance declaration at Control/DeepSeq.hs:917:10-38
      Possible fix:
        add (NFData a1) to the context of a quantified context
    • In the instance declaration for ‘NFData1 ((,) a)’
    |
917 | instance (NFData a) => NFData1 ((,) a) where liftRnf = liftRnf2 rnf
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Control/DeepSeq.hs:919:10: error: [GHC-39999]
    • No instance for ‘NFData a’
        arising from the superclasses of an instance declaration
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData2 (,)’
    |
919 | instance NFData2 (,) where
    |          ^^^^^^^^^^^

Control/DeepSeq.hs:926:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData a1, NFData a2)
        bound by the instance declaration
        at Control/DeepSeq.hs:(926,10)-(927,29)
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 ((,,) a1 a2)’
    |
926 | instance (NFData a1, NFData a2) =>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^...

Control/DeepSeq.hs:929:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: NFData a1
        bound by the instance declaration
        at Control/DeepSeq.hs:(929,10)-(930,26)
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData2 ((,,) a1)’
    |
929 | instance (NFData a1) =>
    |          ^^^^^^^^^^^^^^...

Control/DeepSeq.hs:936:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData a1, NFData a2, NFData a3)
        bound by the instance declaration
        at Control/DeepSeq.hs:(936,10)-(937,33)
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 ((,,,) a1 a2 a3)’
    |
936 | instance (NFData a1, NFData a2, NFData a3) =>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

Control/DeepSeq.hs:939:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData a1, NFData a2)
        bound by the instance declaration
        at Control/DeepSeq.hs:(939,10)-(940,30)
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData2 ((,,,) a1 a2)’
    |
939 | instance (NFData a1, NFData a2) =>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^...

Control/DeepSeq.hs:946:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData a1, NFData a2, NFData a3, NFData a4)
        bound by the instance declaration
        at Control/DeepSeq.hs:(946,10)-(947,37)
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData1 ((,,,,) a1 a2 a3 a4)’
    |
946 | instance (NFData a1, NFData a2, NFData a3, NFData a4) =>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

Control/DeepSeq.hs:949:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData a1, NFData a2, NFData a3)
        bound by the instance declaration
        at Control/DeepSeq.hs:(949,10)-(950,34)
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData2 ((,,,,) a1 a2 a3)’
    |
949 | instance (NFData a1, NFData a2, NFData a3) =>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

Control/DeepSeq.hs:956:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData a1, NFData a2, NFData a3, NFData a4,
                         NFData a5)
        bound by the instance declaration
        at Control/DeepSeq.hs:(956,10)-(957,41)
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for
        ‘NFData1 ((,,,,,) a1 a2 a3 a4 a5)’
    |
956 | instance (NFData a1, NFData a2, NFData a3, NFData a4, NFData a5) =>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

Control/DeepSeq.hs:959:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData a1, NFData a2, NFData a3, NFData a4)
        bound by the instance declaration
        at Control/DeepSeq.hs:(959,10)-(960,38)
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for ‘NFData2 ((,,,,,) a1 a2 a3 a4)’
    |
959 | instance (NFData a1, NFData a2, NFData a3, NFData a4) =>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

Control/DeepSeq.hs:966:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData a1, NFData a2, NFData a3, NFData a4,
                         NFData a5, NFData a6)
        bound by the instance declaration
        at Control/DeepSeq.hs:(966,10)-(967,45)
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for
        ‘NFData1 ((,,,,,,) a1 a2 a3 a4 a5 a6)’
    |
966 | instance (NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6) =>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

Control/DeepSeq.hs:969:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData a1, NFData a2, NFData a3, NFData a4,
                         NFData a5)
        bound by the instance declaration
        at Control/DeepSeq.hs:(969,10)-(970,42)
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for
        ‘NFData2 ((,,,,,,) a1 a2 a3 a4 a5)’
    |
969 | instance (NFData a1, NFData a2, NFData a3, NFData a4, NFData a5) =>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

Control/DeepSeq.hs:976:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData a1, NFData a2, NFData a3, NFData a4,
                         NFData a5, NFData a6, NFData a7)
        bound by the instance declaration
        at Control/DeepSeq.hs:(976,10)-(977,49)
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for
        ‘NFData1 ((,,,,,,,) a1 a2 a3 a4 a5 a6 a7)’
    |
976 | instance (NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7) =>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

Control/DeepSeq.hs:979:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData a1, NFData a2, NFData a3, NFData a4,
                         NFData a5, NFData a6)
        bound by the instance declaration
        at Control/DeepSeq.hs:(979,10)-(980,46)
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for
        ‘NFData2 ((,,,,,,,) a1 a2 a3 a4 a5 a6)’
    |
979 | instance (NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6) =>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

Control/DeepSeq.hs:986:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData a1, NFData a2, NFData a3, NFData a4,
                         NFData a5, NFData a6, NFData a7, NFData a8)
        bound by the instance declaration
        at Control/DeepSeq.hs:(986,10)-(987,53)
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for
        ‘NFData1 ((,,,,,,,,) a1 a2 a3 a4 a5 a6 a7 a8)’
    |
986 | instance (NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7, NFData a8) =>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

Control/DeepSeq.hs:989:10: error: [GHC-39999]
    • Could not deduce ‘NFData a’
        arising from the superclasses of an instance declaration
      from the context: (NFData a1, NFData a2, NFData a3, NFData a4,
                         NFData a5, NFData a6, NFData a7)
        bound by the instance declaration
        at Control/DeepSeq.hs:(989,10)-(990,50)
      Possible fix: add (NFData a) to the context of a quantified context
    • In the instance declaration for
        ‘NFData2 ((,,,,,,,,) a1 a2 a3 a4 a5 a6 a7)’
    |
989 | instance (NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7) =>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
Failed, no modules loaded.

The result did not change after specifying -XImpredicativeTypes.

@mixphix
Copy link
Collaborator

mixphix commented Jan 21, 2023

(fyi, @Icelandjack)

@phadej
Copy link
Contributor Author

phadej commented Jan 22, 2023

-class (forall a. NFData (f a)) => NFData1 f where
+class (forall a. NFData a => NFData (f a)) => NFData1 f where

@mixphix
Copy link
Collaborator

mixphix commented Jan 22, 2023

Oh, with this change (and class (forall a. NFData a => NFData1 (p a)) => NFData2 p) the module compiles. Thanks!

@mixphix
Copy link
Collaborator

mixphix commented Jan 22, 2023

Hm. The new typeclass instances for Sum and Product (and Compose) don't permit the same definition of rnf.

#if MIN_VERSION_base(4,12,0)
-- | @since 1.4.9.0
instance (NFData (f a), NFData (g a)) => NFData (Functor.Product f g a)
  -- where rnf = rnf1
  -- • Could not deduce (NFData (f a1))
  --     arising from a superclass required to satisfy ‘NFData1 f’,
  --     arising from a use of ‘rnf1’
  --   from the context: (NFData (f a), NFData (g a))
  --     bound by the instance declaration
  --     at /Users/mbrown/Documents/Code/Haskell/deepseq/Control/DeepSeq.hs:535:10-71
  --   or from: NFData a1
  --     bound by a quantified context
  --     at /Users/mbrown/Documents/Code/Haskell/deepseq/Control/DeepSeq.hs:536:9-12
  -- • In the expression: rnf1
  --   In an equation for ‘rnf’: rnf = rnf1
  --   In the instance declaration for ‘NFData (Functor.Product f g a)’
#else
-- | @since 1.4.3.0
instance (NFData1 f, NFData1 g, NFData a) => NFData (Functor.Product f g a) where
  rnf = rnf1
#endif

@phadej
Copy link
Contributor Author

phadej commented Jan 23, 2023

don't permit the same definition of rnf.>

  1. Use the same instance (NFData (f a), NFData (g a)) => NFData (Functor.Product f g a) definition. Otherwise it will be painful for the downstream to write compatible code. They would need to case on both base and deepseq versions.

Then instance can be written by hand

instance (NFData (f a), NFData (g a)) => NFData (Functor.Product f g a) where
  rnf (Pair x y) = rnf x `seq` rnf y

The Eq instance for Product in new base is derived:

deriving instance (Eq (f a), Eq (g a)) => Eq (Product f g a)

but the GHC just writes

instance (Eq (f a), Eq (g a)) => Eq (Product f g a) where
  Pair x y == Pair u v = x == u && y == v

for us. In other words It's not possible to share code between Eq1 and Eq. Eq instance requires less from the context, in particular it doesn't (directly) require Eq a. That was one point of CLC proposal. (Instance becomes polykinded, that's worth checking as well with DataKinds e.g.).

@mixphix
Copy link
Collaborator

mixphix commented Feb 15, 2023

Fixed by #95.

@mixphix mixphix closed this as completed Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants