Skip to content
GitLab
Projects Groups Snippets
  • /
  • 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 5,345
    • Issues 5,345
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 568
    • Merge requests 568
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #22543
Closed
Open
Issue created Dec 01, 2022 by syd@cs-syd.eu@kerckhove_tsContributor

A `a` -> `id a` transformation does not preserve "it type-checks"

Summary

I am trying to write a ghc plugin for code coverage: See the plan here: https://github.com/NorfairKing/dekking#source-to-source-transformation

Replacing every expression a by id a produces code that does not type-check.

Steps to reproduce

Examples (using servant-server-19.2:

This type-checks:

hoistExampleServer :: Server EmptyAPI
hoistExampleServer = hoistServerWithContext (Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer

This does not:

hoistExampleServer :: Server EmptyAPI
hoistExampleServer = (id hoistServerWithContext) (Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer

This is the error (with GHC 9.0.2):

src/ServantExample.hs:47:26: error:
    • Couldn't match type: forall x. m0 x -> Handler x
                     with: a0 -> a0
      Expected: Proxy EmptyAPI
                -> Proxy '[]
                -> (a0 -> a0)
                -> Tagged m0 EmptyServer
                -> Tagged Handler EmptyServer
        Actual: Proxy EmptyAPI
                -> Proxy '[]
                -> (forall x. m0 x -> Handler x)
                -> ServerT EmptyAPI m0
                -> ServerT EmptyAPI Handler
    • In the first argument of ‘id’, namely ‘hoistServerWithContext’
      In the expression:
        (id hoistServerWithContext)
          (Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer
      In an equation for ‘hoistExampleServer’:
          hoistExampleServer
            = (id hoistServerWithContext)
                (Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer
   |
47 | hoistExampleServer = (id hoistServerWithContext) (Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer

This is the error (with GHC 9.2.4):

src/ServantExample.hs:47:26: error:
    • Couldn't match expected type: forall x. m0 x -> Handler x
                  with actual type: a0 -> a0
    • In the first argument of ‘id’, namely ‘hoistServerWithContext’
      In the expression:
        (id hoistServerWithContext)
          (Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer
      In an equation for ‘hoistExampleServer’:
          hoistExampleServer
            = (id hoistServerWithContext)
                (Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer
   |
47 | hoistExampleServer = (id hoistServerWithContext) (Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer
   |                          ^^^^^^^^^^^^^^^^^^^^^^

Even with ImpredicateTypes and DeepSubsumption, this does not compile.

Expected behavior

GHC should accept this (I think).

Environment

  • GHC version used: GHC 9.0.2 and GHC 9.2.4

Optional:

  • Operating System: NixOS
  • System Architecture: x86_64-linux
Edited Dec 01, 2022 by syd@cs-syd.eu
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking