[GHC] #15869: Discrepancy between seemingly equivalent type synonym and type family

GHC ghc-devs at haskell.org
Wed Nov 7 16:10:03 UTC 2018


#15869: Discrepancy between seemingly equivalent type synonym and type family
-------------------------------------+-------------------------------------
        Reporter:  RyanGlScott       |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler (Type    |              Version:  8.6.2
  checker)                           |
      Resolution:                    |             Keywords:  TypeFamilies
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  GHC rejects       |  Unknown/Multiple
  valid program                      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 This isn't the only discrepancy I've encountered (although this is the
 most prominent example that I've uncovered). Another, slightly more minor
 discrepancy can be found in this program:

 {{{#!hs
 {-# LANGUAGE DataKinds #-}
 {-# LANGUAGE ImpredicativeTypes #-}
 {-# LANGUAGE PolyKinds #-}
 {-# LANGUAGE TypeFamilies #-}
 {-# OPTIONS_GHC -Wall -fprint-explicit-foralls #-}
 module Bug where

 import Data.Kind

 type KindOf1 (a :: k) = k
 type family KindOf2 (a :: k) :: Type where
   KindOf2 (a :: k) = k

 data A (a :: Type) :: a -> Type

 f :: KindOf1 A
 f = undefined

 g = f
 h = g
 }}}

 Compiling this yields the following warnings:

 {{{
 $ /opt/ghc/8.6.2/bin/ghci Bug.hs
 GHCi, version 8.6.2: http://www.haskell.org/ghc/  :? for help
 Loaded GHCi configuration from /home/rgscott/.ghci
 [1 of 1] Compiling Bug              ( Bug.hs, interpreted )

 Bug.hs:19:1: warning: [-Wmissing-signatures]
     Top-level binding with no type signature: g :: forall {a}. a -> *
    |
 19 | g = f
    | ^

 Bug.hs:20:1: warning: [-Wmissing-signatures]
     Top-level binding with no type signature: h :: forall {a}. a -> *
    |
 20 | h = g
    | ^
 }}}

 Note the inferred type signatures for `g` and `h` (Side note: it's a bit
 weird that their inferred types are `forall {a}. a -> *` and not, say,
 `forall a -> a -> *`. But that's not the main issue here.)

 Now, if you redefine `f` to use `KindOf2` in its type signature:

 {{{#!hs
 f :: KindOf2 A
 f = undefined
 }}}

 Recompiling the module will instead yield these warnings:

 {{{
 $ /opt/ghc/8.6.2/bin/ghci Bug.hs
 GHCi, version 8.6.2: http://www.haskell.org/ghc/  :? for help
 Loaded GHCi configuration from /home/rgscott/.ghci
 [1 of 1] Compiling Bug              ( Bug.hs, interpreted )

 Bug.hs:19:1: warning: [-Wmissing-signatures]
     Top-level binding with no type signature: g :: forall a -> a -> *
    |
 19 | g = f
    | ^

 Bug.hs:20:1: warning: [-Wmissing-signatures]
     Top-level binding with no type signature: h :: forall {a}. a -> *
    |
 20 | h = g
    | ^
 }}}

 Notice that the inferred type of `g` is now `forall a -> a -> *`, whereas
 before it was `forall {a}. a -> *`! Quite strange. (And to make things
 stranger, the inferred type of `h` is different from that of `g`.)

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15869#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list