False orphan instance warning for multi-parameter type class instance
Summary
GHC generates orphan instance warning for a multi-param class instance, which is located in the same module with one of type parameters, meanwhile another type parameter is defined in another module. IMHO orphan instance warning is false positive.
Steps to reproduce
-- A.hs
module A where
data TofA
-- C.hs
{-# LANGUAGE FunctionalDependencies #-}
module C where
class Cof2 a b | a -> b where
-- B.hs
module B where
import A
import C
data TofB
instance Cof2 TofA TofB where
Orphan instance: instance Cof2 TofA TofB
To avoid this
move the instance declaration to the module of the class or of the type, or
wrap the type with a newtype and declare the instance on the new type.
Expected behavior
Absence of orphan instance warning
Environment
- GHC version used: 9.2.5
Optional:
- Operating System: nix-shell on top of Debian
- https://github.com/NixOS/nixpkgs/archive/aa478e283bb5c73b2cdd2f891251f0d669517b63.tar.gz
- System Architecture: intel 64bit