Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • 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 4,829
    • Issues 4,829
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 445
    • Merge requests 445
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #2247

Closed
Open
Created Apr 28, 2008 by claus.reinke@talk21.com@trac-claus.reinke

GHC accepts FD violations, unless the conflicing instances are used

consider

class FD a b | a -> b
instance CFD a b => FD a b

class {- FD a b => -} CFD a b
instance CFD Bool Char
instance CFD Bool Bool

f :: CFD Bool Bool => Bool
f = True

g :: CFD Bool Char => Bool
g = False

f' :: FD Bool Bool => Bool
f' = True

g' :: FD Bool Char => Bool
g' = False

the class instance for FD is odd, because there is no guarantee that instances of CFD comply to the FD (and Hugs rejects that instance, unless the superclass constraint for CFD is uncommented). as it stands, this code specifies two FD-conflicting instances of class FD, but they are implied, not explicit.

GHCi accepts this code, and only complains if the two conflicting instances are used, explicitly, in the same expression:

*Main> f
True
*Main> g
False
*Main> (f,g)
(True,False)
*Main> f'
True
*Main> g'
False
*Main> (f',g')

<interactive>:1:0:
    Couldn't match expected type `Bool' against inferred type `Char'
    When using functional dependencies to combine
      FD Bool Char, arising from a use of `g'' at <interactive>:1:4-5
      FD Bool Bool, arising from a use of `f'' at <interactive>:1:1-2
    When generalising the type(s) for `it'
*Main> do {let {x=f} ;let {y=g} ; return (x,y) }
(True,False)
*Main> do {let {x=f'} ;let {y=g'} ; return (x,y) }

<interactive>:1:0:
    Couldn't match expected type `Char' against inferred type `Bool'
    When using functional dependencies to combine
      FD Bool Bool, arising from a use of `f'' at <interactive>:1:11-12
      FD Bool Char, arising from a use of `g'' at <interactive>:1:23-24
    When generalising the type(s) for `it'
*Main> let x=f'
*Main> let y=g'
*Main> (x,y)
(True,False)

so we can have FD-conflicting instances in the same code, even use them in the same GHCi session, as long as they don't meet in the same line..

for further details and questions, see this message: some questions about type improvement, FDs vs TFs, and Hugs vs GHCi

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