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,832
    • Issues 4,832
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 450
    • Merge requests 450
  • 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
  • #19044

Closed
Open
Created Dec 09, 2020 by Ryan Scott@RyanGlScottMaintainer

Regression: HEAD requires FlexibleContexts because of inferred, redundant constraint

Originally observed in a head.hackage build here.

The following code, minimized from the pandoc-2.11.2 library, fails to typecheck on GHC HEAD (I tried using commit 62ed6957) but does typecheck with GHC 8.10.2 and 9.0.1-alpha1:

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Bug where

class C a b where
  m :: a -> b

instance C a a where
  m = id

instance C a (Maybe a) where
  m _ = Nothing

f :: a -> Maybe a
f = g
  where
    g x = h (m x) x

h :: Maybe a -> a -> Maybe a
h = const

On HEAD, this produces the following error:

$ ~/Software/ghc-9.1.0.20201208/bin/ghc Bug.hs
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

Bug.hs:17:5: error:
    • Non type-variable argument in the constraint: C a1 (Maybe a1)
      (Use FlexibleContexts to permit this)
    • When checking the inferred type
        g :: forall {a}. C a (Maybe a) => a -> Maybe a
      In an equation for ‘f’:
          f = g
            where
                g x = h (m x) x
   |
17 |     g x = h (m x) x
   |     ^^^^^^^^^^^^^^^

Previous versions of GHC would accept this program because the inferred type of g was forall {a}. a -> Maybe a, not g :: forall {a}. C a (Maybe a) => a -> Maybe a. The presence of this extra C a (Maybe a) constraint (which seems redundant?) is suspicious, so I opted to open an issue about it.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking