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,312
    • Issues 4,312
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 385
    • Merge Requests 385
  • 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
  • #14386

Closed
Open
Opened Oct 25, 2017 by Icelandjack@IcelandjackReporter

GHC doesn't allow Coercion between partly-saturated type constructors

If I define an "opposite category" newtype Op cat a b = Op (cat b a) then representationally it forms an involution: applying Op twice gives the same representation as not applying it at all

$ ... -ignore-dot-ghci
GHCi, version 8.3.20170920: http://www.haskell.org/ghc/  :? for help
Prelude> import Data.Coerce
Prelude Data.Coerce> import Data.Type.Coercion 
Prelude Data.Coerce Data.Type.Coercion> newtype Op cat a b = Op (cat b a)
Prelude Data.Coerce Data.Type.Coercion> :t coerce :: Op (Op cat) a b -> cat a b
coerce :: Op (Op cat) a b -> cat a b :: Op (Op cat) a b -> cat a b
Prelude Data.Coerce Data.Type.Coercion> :t Coercion :: Coercion (Op (Op cat) a b) (cat a b)
Coercion :: Coercion (Op (Op cat) a b) (cat a b)
  :: Coercion (Op (Op cat) a b) (cat a b)

But these don't work:

Prelude Data.Coerce Data.Type.Coercion> :t Coercion :: Coercion (Op (Op cat) a) (cat a)

<interactive>:1:1: error:
    • Couldn't match representation of type ‘Op (Op cat1) a1’
                               with that of ‘cat1 a1’
        arising from a use of ‘Coercion’
    • In the expression: Coercion :: Coercion (Op (Op cat) a) (cat a)
Prelude Data.Coerce Data.Type.Coercion> :t Coercion :: Coercion (Op (Op cat) cat

<interactive>:1:38: error:
    parse error (possibly incorrect indentation or mismatched brackets)
Prelude Data.Coerce Data.Type.Coercion> :t Coercion :: Coercion (Op (Op cat)) cat

<interactive>:1:1: error:
    • Couldn't match representation of type ‘cat1’
                               with that of ‘Op (Op cat1)’
        arising from a use of ‘Coercion’
      ‘cat1’ is a rigid type variable bound by
        an expression type signature:
          forall (cat1 :: * -> * -> *). Coercion (Op (Op cat1)) cat1
        at <interactive>:1:13-38
    • In the expression: Coercion :: Coercion (Op (Op cat)) cat

I'm wondering if this is intentional

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