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,400
    • Issues 5,400
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 590
    • Merge requests 590
  • 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
  • #15637
Closed
Open
Issue created Sep 13, 2018 by i-am-tom@trac-i-am-tom

Ambiguous type variables in GeneralisedNewtypeDeriving

When deriving the C instance in the following code:

{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
module Test where

class C a where f :: String

instance C () where f = "foo"

newtype T = T () deriving C

The following error occurs:

Test.hs:10:27: error:
    • Ambiguous type variable ‘a0’ arising from a use of ‘f’
      prevents the constraint ‘(C a0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘a0’ should be.
      These potential instances exist:
        instance C T -- Defined at Test.hs:10:27
        instance C () -- Defined at Test.hs:8:10
    • In the third argument of ‘GHC.Prim.coerce’, namely ‘f’
      In the expression: GHC.Prim.coerce @String @String f :: String
      In an equation for ‘f’:
          f = GHC.Prim.coerce @String @String f :: String
      When typechecking the code for ‘f’
        in a derived instance for ‘C T’:
        To see the code I am typechecking, use -ddump-deriv
   |
10 | newtype T = T () deriving C
   |                           ^
  1. .. and the following core is produced:
==================== Derived instances ====================
Derived class instances:
  instance Test.C Test.T where
    Test.f
      = GHC.Prim.coerce @GHC.Base.String @GHC.Base.String Test.f ::
          GHC.Base.String


Derived type family instances:

The problem seems to be that the a should have been set to () within the coerced instance. I've been working round this with a newtype X a = X String as the result value so that the a is present in the signature, but I think this is a bug; should a more specialised instance be generated? I hope this is enough of an explanation!

Thanks, Tom

Trac metadata
Trac field Value
Version 8.4.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking