2

Pragma OverlappingInstances 在 GHC 中被弃用了一段时间,而 OVERLAPPING pragma 是它的替代品。

instance {-# OVERLAPPING #- } ...

虽然这不是 Haskell 中定义类实例的唯一方法。我无法通过派生来定义重叠实例,并避免对已弃用的 OverlappingInstances 发出讨厌的警告。

以下情况均无效:

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

1 回答 1

3

您需要StandaloneDeriving用于此类实例以及需要专门实例上下文的实例。

{-# 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)
于 2021-04-28T17:46:56.533 回答