Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 5.5k
    • Issues 5.5k
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 624
    • Merge requests 624
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #23143
Closed
Open
Issue created Mar 20, 2023 by Ben Price@brpriceDeveloper

GHC 9.6 incorrect redundant constraint warning with generalized newtype deriving

Summary

GHC 9.6 introduces a new -Wredundant-constraints warning in derived code. This is not present in 9.4. It is also not present in a manually written instance. I believe that the constraint is actually necessary.

Steps to reproduce

Compile the following code with GHC 9.6, mtl-2.3.1 and transformers-0.6.1.0:

{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Bug where

import Control.Monad.Reader
import Control.Applicative
import Data.Coerce

newtype NullDbT m a = NullDbT {unNullDbT :: ReaderT Int m a}
  deriving newtype
    ( Functor
    , Applicative
    , Alternative
    , Monad
    , MonadTrans -- GHC complains the monad constraint is redundant
    )

class (forall m. Monad m => Monad (t m)) => C t where
  myLift :: Monad m => m a -> t m a

instance C NullDbT where 
  -- Monad constraint is required (GHC errors if it is not present, with either implementation)
  myLift :: forall m a . Monad m => m a -> NullDbT m a
  --myLift x = NullDbT (lift @(ReaderT Int) x)
  myLift = coerce @(m a -> ReaderT Int m a) @(m a -> NullDbT m a) (lift @(ReaderT Int))

Expected behavior

I expect consistent warnings/errors between the derived code and a manually written copy. In particular here, I believe that the constraint is necessary, since it is needed for the lift @(ReaderT Int) call.

Environment

  • GHC version used: 9.6

Optional:

  • Operating System: NixOS
  • System Architecture: x86_64
Edited Mar 20, 2023 by Ben Price
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking