Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,391
    • Issues 4,391
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 372
    • Merge Requests 372
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #7487

Closed
Open
Opened Dec 06, 2012 by spl@trac-spl

Deriving Generic1 for a type containing Either

With the following code:

{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics
data T a = C (Either Int a) deriving Generic1

I get the error message:

Main.hs:3:38:
    Can't make a derived instance of `Generic1 T':
      must not apply type constructors that cannot be represented with `Rep1'
      (such as `Either') to arguments that involve the last type parameter
    In the data declaration for `T'

But when I look at the instances of Generic1, I see the following (summarized):

*Main> :i Generic1
...
instance Generic1 (Either a) -- Defined in `GHC.Generics'
...

So, it seems that Either a can be represented with Rep1. Consequently, the error message is a bit confusing.

Similarly, I can define my own version of Either -- e.g. data U a b = A a | B b deriving Generic1 -- replace Either with U and still get the message. I also get this problem using U as data U a b = U a b deriving Generic1 but not with T as data T a = C (Int, a) deriving Generic1.

Lastly, I try this:

data T a = C (Either Int (T a)) deriving Generic1

but the error is even stranger here:

Main.hs:3:38:
    Can't make a derived instance of `Generic1 T':
      must not apply type constructors that cannot be represented with `Rep1'
      (such as `T') to arguments that involve the last type parameter
    In the data declaration for `T'

What's the general problem with these examples?

  • Can the error message be improved?
  • Can the deriving mechanism be extended for these types?

I'm assuming I can write my own Generic1 instance, though I haven't actually tried.

Trac metadata
Trac field Value
Version 7.6.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#7487