Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,243
    • Issues 5,243
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 570
    • Merge requests 570
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #14190
Closed
Open
Issue created Sep 07, 2017 by David Feuer@treeowlReporter

Typeable imposes seemingly redundant constraints on polykinded instances

See also #21822 (closed), #16627.

To derive Data for Const, we need

deriving instance (Typeable k, Data a, Typeable (b :: k)) => Data (Const a b)

Where's that Typeable k constraint come from? It turns out that for reasons I haven't looked into, we can only obtain Typeable (Const a (b :: k)) if we have Typeable k; (Typeable a, Typeable b) is insufficient. Is there a reason for that?

Annoyingly, we can actually get that:

weGotThat :: forall k (a :: k). Typeable a :- Typeable k
weGotThat = Sub $ withTypeable (typeRepKind (typeRep :: TypeRep a)) Dict

But of course that doesn't help us.

Could we use UndecidableSuperClasses to work around this problem? I think we likely can, although I'm concerned about the performance implications:

class (Typeable a, Typeable' k) => Typeable' (a :: k)
instance (Typeable a, Typeable' k) => Typeable' (a :: k)

withTypeable' :: forall k (a :: k) r. TypeRep a -> (Typeable' a => r) -> r
withTypeable' tr f = withTypeable tr $ withTypeable (typeRepKind (typeRep @a)) f
Trac metadata
Trac field Value
Version 8.2.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC bgamari
Operating system
Architecture
Edited Jul 11, 2022 by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking