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,252
    • Issues 4,252
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 398
    • Merge Requests 398
  • 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
  • #14896

Closed
Open
Opened Mar 06, 2018 by Icelandjack@IcelandjackReporter

QuantifiedConstraints: GHC does doesn't discharge constraints if they are quantified

This came up on a reddit thread,

{-# Language QuantifiedConstraints #-}

class (forall aa. Functor (bi aa)) => Bifunctor bi where
  first :: (a -> a') -> (bi a b -> bi a' b)

bimap :: Bifunctor bi => (a -> a') -> (b -> b') -> (bi a b -> bi a' b')
bimap f g = first f . fmap g

This is the type we want for bimap even if we mix & match Bifunctor and Functor. We already know that we can fmap @(bi xx) for any xx but this is not the inferred type.

Instead GHC infers a type (tidied up) with a superfluous Functor constraint

bimap :: (Bifunctor bi, Functor (bi a)) => (a -> a') -> (b -> b') -> (bi a b -> bi a' b')

Indeed post-composing with a superfluous fmap @(bi a') id incurs yet another Functor constraint

bimap :: (Bifunctor bi, Functor (bi a), Functor (bi a')) => (a -> a') -> (b -> b') -> (bi a b -> bi a' b')
bimap f g = fmap id . first f . fmap g

A terminology question, I'm not sure how to phrase what GHC isn't doing to the Functor constraints: ‘discharge’?

Edited Mar 10, 2019 by Icelandjack
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#14896