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,322
    • Issues 4,322
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 362
    • Merge Requests 362
  • 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
  • #14010

Closed
Open
Opened Jul 22, 2017 by Vladislav Zavialov@int-indexDeveloper

UndecidableSuperClasses - Could not deduce (Category d)

Consider this well-typed code:

{-# LANGUAGE NoImplicitPrelude, TypeInType, TypeFamilies,
             UndecidableSuperClasses, RankNTypes, TypeOperators,
             FlexibleContexts, TypeSynonymInstances, FlexibleInstances,
             UndecidableInstances #-}
module Monolith where

import Data.Kind (Type)
import GHC.Exts (Constraint)

type family (~>) :: c -> c -> Type

type instance (~>) = (->)
type instance (~>) = ArrPair

type family Fst (p :: (a, b)) :: a where
  Fst '(x, _) = x

type family Snd (p :: (a, b)) :: b where
  Snd '(_, y) = y

data ArrPair a b = ArrPair (Fst a ~> Fst b) (Snd a ~> Snd b)

type family Super c :: Constraint where
  Super Type = ()
  Super (c, d) = (Category c, Category d)

class Super cat => Category cat where
  id :: forall (a :: cat). a ~> a

instance Category Type where
  id = \x -> x

instance (Category c, Category d) => Category (c, d) where
  id = ArrPair id id

class Category (c, d) => Functor (f :: c -> d) where
--class (Category c, Category d) => Functor (f :: c -> d) where
  map :: (a ~> b) -> (f a ~> f b)

data OnSnd f a b = OnSnd (f '(a, b))

instance Functor (f :: (c, d) -> Type) => Functor (OnSnd f a) where
  map f (OnSnd x) = OnSnd (map (ArrPair id f) x)

The compiler accepts it. But if I change the definition of 'Functor' for the commented one, I get an error:

super.hs:39:10: error:
    • Could not deduce (Category d)
        arising from the superclasses of an instance declaration
      from the context: Functor f
        bound by the instance declaration at super.hs:39:10-61
      Possible fix:
        add (Category d) to the context of the instance declaration
    • In the instance declaration for ‘Functor (OnSnd f a)’
   |
39 | instance Functor (f :: (c, d) -> Type) => Functor (OnSnd f a) where
   |

I can reproduce this on 8.0.1, 8.2.0.20170704 and HEAD.

Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC simonpj
Operating system
Architecture
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#14010