Skip to content

GitLab

  • Menu
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 4,868
    • Issues 4,868
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 458
    • Merge requests 458
  • 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 Compiler
  • GHCGHC
  • Issues
  • #19802
Closed
Open
Created May 06, 2021 by Richard Eisenberg@raeDeveloper

Pure unifier is incomplete around casts and AppTys: instance lookup fails

The pure unifier (in GHC.Core.Unify) is incomplete with respect to casts. Here is the counter-example:

alpha :: Type -> Type   -- this is the template variable
a :: Type -> k 
co :: k ~ Type

(alpha Int)     ~?      (a Int |> co)

Today, the pure unifier will claim that these two types have no unifier. But they do:

alpha :-> a |> <Type> -> co

This, unfortunately, will not be easy to solve. We will have to somehow remember the casts that we see as we descend into a type, and use those casts for rewriting.

Here is a concrete program that witnesses the problem:

{-# LANGUAGE FlexibleInstances, TypeFamilies, ExplicitForAll, KindSignatures,
             DataKinds #-}

module Bug where

import Data.Kind ( Type )

class C a where
  meth :: a -> ()
instance C (b Int) where
  meth _ = ()

type family Star where
  Star = Type

f :: forall (c :: Type -> Star). c Int -> ()
f x = meth x

As written, it fails with

Bug.hs:17:7: error:
    • No instance for (C (c Int)) arising from a use of ‘meth’
    • In the expression: meth x
      In an equation for ‘f’: f x = meth x
   |
17 | f x = meth x
   |       ^^^^^^

But change the type of c to become Type -> Type, and the program is accepted.

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