Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 5.5k
    • Issues 5.5k
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 635
    • Merge requests 635
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Model experiments
  • Analytics
    • Analytics
    • 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
  • #1624

internal error caused by adding an instance to a type class with a functional dependency and a default method

I've got trouble with the following program:

{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
class Foo a b | a -> b where
    foo :: a -> b
    foo = undefined

instance Foo a (Maybe a)

This results in a type checking error, and an internal error:

xx.hs:2:0:
    Couldn't match expected type `b' (a rigid variable)
           against inferred type `Maybe a'
      `b' is bound by the class declaration for `Foo'
    When using functional dependencies to combine
      Foo a (Maybe a), arising from the instance declaration at x.hs:8:0
      Foo a b,
        arising from is bound by the class declaration for `Foo'
        at x.hs:(2,0)-(4,18)
[snip]
x.hs:6:0:
    GHC internal error: `Main.$dmfoo' is not in scope
    In the expression: Main.$dmfoo
    In the definition of `foo': foo = Main.$dmfoo
    In the definition for method `foo'

Slightly less convincing variations on the scheme are

class Foo a b | a -> b
instance Foo a (Maybe a)

foo :: Foo a b => a -> b
foo = undefined

class Bar a b c

instance (Foo a b, Foo b c) => Bar a b c

Both the definition of foo and the instance declaration of Bar give a type checking error "when combining functional dependencies".

Apparently ghc doesn't use functional dependencies to simplify the contexts of user supplied type signatures; I think the above examples indicate that it should.

Trac metadata
Trac field Value
Version 6.7
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
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