Skip to content

Deriving instances for SOP functors using phantom types #182

@fpringle

Description

@fpringle

Hi, not sure if this is the right place to ask, but I have an issue regarding Show and Eq instances for NP and NS types of functors that don't use their type parameter. The functors in my specific use-case are {Field,Constructor}Info, but the simplest example I can think of is Proxy:

newtype Proxies xs = Proxies (NP Proxy xs)
  deriving (Show)

This gives the following type error, which of course makes sense based on the superclass for Show (NS f xs) using All rather than QuantifiedConstraints:

src/Diff.hs:36:13-16: error: [GHC-05617]
     Could not solve: (AllF (Compose Show Proxy) xs, AllF Top xs)
        arising from a superclass required to satisfy All (Compose Show Proxy) xs,
        arising from the first field of Proxies (type NP Proxy xs)
     When deriving the instance for (Show (Proxies xs))
   |
36 |   deriving (Show)
   |             ^^^^
src/Diff.hs:36:13-16: error: [GHC-39999]
     No instance for All (Compose Show Proxy) xs
        arising from the first field of Proxies (type NP Proxy xs)
      Possible fix:
        use a standalone 'deriving instance' declaration,
          so you can specify the instance context yourself
     When deriving the instance for (Show (Proxies xs))
   |
36 |   deriving (Show)

Is there any way I can convince GHC that Proxies has a valid Show instance regardless of what xs is, while still getting a derived instance for free? Something like

deriving instance (forall x. Show (Proxy x)) => Show (Proxies xs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions