Daniil Iaitskov
Daniil Iaitskov

Reputation: 6089

How to apply overlapping pragma to derived instance

Pragma OverlappingInstances is deprecated in GHC for quite awhile and OVERLAPPING pragma is a substitute for that.

instance {-# OVERLAPPING #- } ...

Though this is not the only way in Haskell to define a class instance. I cannot define overlapping instance through deriving and avoid pesky warning about deprecated OverlappingInstances.

None of below cases are working:

  deriving {-# OVERLAPPING #-} (Lift)
  deriving ({-# OVERLAPPING #-} Lift)

Upvotes: 2

Views: 209

Answers (1)

dfeuer
dfeuer

Reputation: 48631

You need to use StandaloneDeriving for such instances, as well as for ones that need specialized instance contexts.

{-# language StandaloneDeriving, FlexibleInstances #-}

data T a = T

deriving instance {-# OVERLAPPING #-} Show (T Int)
instance {-# OVERLAPPABLE #-} Show (T a) where
  show ~T = "Tee-hee"

main = do
  print (T :: T Int)
  print (T :: T Char)

Upvotes: 4

Related Questions