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,324
    • Issues 4,324
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 384
    • Merge Requests 384
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #7641

Closed
Open
Opened Jan 31, 2013 by Michael Snoyman@snoyberg

Incorrect reporting of overlapping instances

I've reproduced this issue on both 7.6.1 and 7.6.2. It does not exist on 7.4.2.

Given the following code (simplified from an actual case in Yesod):

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}

data Foo b = Foo deriving Show

class ToFoo a b where
    toFoo :: a -> Foo b

instance ToFoo (c -> ()) b where
    toFoo _ = Foo

bar :: Foo ()
bar =
    baz ()
  where
    baz () = toFoo $ \_ -> ()

main :: IO ()
main = print bar

This compiles and runs correctly with 7.4.2, producing the output "Foo". However, with 7.6.1 and 7.6.2 I get the following error message (identical between the two versions):

test.hs:16:5:
    Overlapping instances for ToFoo (t0 -> ()) b
      arising from the ambiguity check for `baz'
    Matching givens (or their superclasses):
      (ToFoo (t -> ()) b)
        bound by the inferred type for `baz':
                   ToFoo (t -> ()) b => () -> Foo b
        at test.hs:16:5-29
    Matching instances:
      instance ToFoo (c -> ()) b -- Defined at test.hs:9:10
    (The choice depends on the instantiation of `b, t0')
    When checking that `baz'
      has the inferred type `forall b t.
                             ToFoo (t -> ()) b =>
                             () -> Foo b'
    Probable cause: the inferred type is ambiguous
    In an equation for `bar':
        bar
          = baz ()
          where
              baz () = toFoo $ \ _ -> ()
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#7641