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,247
    • Issues 4,247
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 393
    • Merge Requests 393
  • 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
  • #15347

Closed
Open
Opened Jul 05, 2018 by aaronvargo@trac-aaronvargo

QuantifiedConstraints: Implication constraints with type families don't work

This may be related to #14860, but I think it's different.

The following code fails to compile:

{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ConstraintKinds #-}

import Prelude()
import Data.Kind

data Dict c = c => Dict

type family F a :: Constraint

foo :: forall a b. (a => F b, a) => Dict (F b)
foo = Dict
• Could not deduce: F b arising from a use of ‘Dict’
  from the context: (a => F b, a)

Yet the following all do compile:

bar :: forall a. F a => Dict (F a)
bar = Dict

baz :: forall a b. (a => b, a) => Dict b
baz = Dict

qux :: forall a b c. (a => c, a, c ~ F b) => Dict (F b)
qux = Dict

It seems that a wanted F b can be solved with a given F b, but not with a given a => F b, which is bizarre. The fact that qux still works is also strange, as it means that you get a different result if you first simplify by substituting c = F b.

As a more practical example, the following similarly fails to compile, due to the Cod f type family:

-- in addition to the above extensions
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}

class Ob p a

class (forall a. Ob (Dom f) a => Ob (Cod f) (f a)) => Functor f where
  type Dom f
  type Cod f

liftOb :: forall f a. (Functor f, Ob (Dom f) a) => Dict (Ob (Cod f) (f a))
liftOb = Dict

While a version which uses fundeps instead does compile:

class (forall a. Ob dom a => Ob cod (f a)) => Functor dom cod f | f -> dom cod

liftOb :: forall f a dom cod. (Functor dom cod f, Ob dom a) => Dict (Ob cod (f a))
liftOb = Dict
Edited Mar 10, 2019 by aaronvargo
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#15347