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,332
    • Issues 4,332
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 370
    • Merge Requests 370
  • 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
  • #16323

Closed
Open
Opened Feb 15, 2019 by pjljvdlaar@trac-pjljvdlaar

Cannot deduce X error with X provided in TypeFamilies

The following code

{-# LANGUAGE FlexibleContexts      #-}
{-# LANGUAGE TypeFamilies          #-}
module TorXakis.Test
( -- * Referable
  Referable(..)
)
where
import           Data.Hashable
import qualified Data.HashMap         as HashMap

-- | A referable class
class Referable a where
    type Ref a
    toRef :: a -> Ref a

-- | Map of Referable objects.
data (Referable a, Ord (Ref a), Hashable (Ref a)) =>
            RefMap a = RefMap { -- | the HashMap
                                toHashMap :: HashMap.Map (Ref a) a
                              } deriving (Eq, Ord, Show, Read)

gives the following errors

C:\TorXakis\sys\txs-basics\src\TorXakis\Test.hs:20:43: error:
    * Could not deduce (Ord (Ref a))
        arising from the 'deriving' clause of a data type declaration
      from the context: (Eq a, Referable a)
        bound by the deriving clause for `Eq (RefMap a)'
        at src\TorXakis\Test.hs:20:43-44
      Possible fix:
        use a standalone 'deriving instance' declaration,
          so you can specify the instance context yourself
    * When deriving the instance for (Eq (RefMap a))
   |
20 |                               } deriving (Eq, Ord, Show, Read)
   |                                           ^^

C:\TorXakis\sys\txs-basics\src\TorXakis\Test.hs:20:47: error:
    * Could not deduce (Hashable (Ref a))
        arising from the 'deriving' clause of a data type declaration
      from the context: (Ord a, Referable a)
        bound by the deriving clause for `Ord (RefMap a)'
        at src\TorXakis\Test.hs:20:47-49
      Possible fix:
        use a standalone 'deriving instance' declaration,
          so you can specify the instance context yourself
    * When deriving the instance for (Ord (RefMap a))
   |
20 |                               } deriving (Eq, Ord, Show, Read)
   |                                               ^^^

C:\TorXakis\sys\txs-basics\src\TorXakis\Test.hs:20:52: error:
    * Could not deduce (Ord (Ref a))
        arising from the 'deriving' clause of a data type declaration
      from the context: (Show a, Referable a)
        bound by the deriving clause for `Show (RefMap a)'
        at src\TorXakis\Test.hs:20:52-55
      Possible fix:
        use a standalone 'deriving instance' declaration,
          so you can specify the instance context yourself
    * When deriving the instance for (Show (RefMap a))
   |
20 |                               } deriving (Eq, Ord, Show, Read)
   |                                                    ^^^^

C:\TorXakis\sys\txs-basics\src\TorXakis\Test.hs:20:58: error:
    * Could not deduce (Ord (Ref a))
        arising from the 'deriving' clause of a data type declaration
      from the context: (Read a, Referable a)
        bound by the deriving clause for `Read (RefMap a)'
        at src\TorXakis\Test.hs:20:58-61
      Possible fix:
        use a standalone 'deriving instance' declaration,
          so you can specify the instance context yourself
    * When deriving the instance for (Read (RefMap a))
   |
20 |                               } deriving (Eq, Ord, Show, Read)
   |                                                          ^^^^

--  While building package txs-basics-0.1.0.0 using:
      C:\sr\setup-exe-cache\x86_64-windows-integersimple\Cabal-simple_Z6RU0evB_2.0.1.0_ghc-8.2.2.exe --builddir=.stack-w
ork\dist\67675594 build lib:txs-basics --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1

yet the requirements such as Ord (Ref a) are clearly given to the data definition!

possibly related to #16319

Trac metadata
Trac field Value
Version 8.2.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Edited Mar 10, 2019 by pjljvdlaar
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#16323