Skip to content

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:

Edited by sheaf
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information