Generalized newtype deriving can cause spurious redundant constraint warning
Consider the following:
{-# LANGUAGE ConstrainedClassMethods #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wredundant-constraints #-}
module Main where
-- declare class
class Mode t where
type Scalar t
myf :: Fractional (Scalar t) => t -> Scalar t -> t
-- declare data type + instance
data ReverseDouble a
instance Mode (ReverseDouble s) where
type Scalar (ReverseDouble s) = Double
myf = undefined
-- declare a newtype and derive the instance from the above data type
newtype GDouble s a = GDouble (ReverseDouble s)
deriving newtype Mode
main :: IO ()
main = pure ()
Compiling this with GHC 8.10.4 yields a warning about a redundant Fractional
constraint on that deriving newtype Mode
line, but this is quite confusing as a user - GHC seems to be warning about its own generated code here (and I'm not even sure it's correct in its self-indictment).