Opened 18 months ago

Closed 16 months ago

Last modified 8 months ago

#11485 closed bug (fixed)

Very unhelpful message resulting from kind mismatch

Reported by: RyanGlScott Owned by:
Priority: normal Milestone: 8.0.1
Component: Compiler (Type checker) Version: 8.0.1-rc1
Keywords: TypeInType Cc: goldfire
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Other Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

The following code:

module Foo where

import Data.Typeable

tyConOf :: Typeable a => Proxy a -> TyCon
tyConOf = typeRepTyCon . typeRep

tcList :: TyCon
tcList = tyConOf (Proxy :: Proxy [])

fails because -XPolyKinds is not enabled. But the error message that you get is quite different on GHC 7.10 and 8.0.

On GHC 7.10.3:

[1 of 1] Compiling Foo              ( Foo.hs, Foo.o )

Foo.hs:9:19:
    Couldn't match kind ‘* -> *’ with ‘*’
    Expected type: Proxy a0
      Actual type: Proxy []
    In the first argument of ‘tyConOf’, namely ‘(Proxy :: Proxy [])’
    In the expression: tyConOf (Proxy :: Proxy [])
    In an equation for ‘tcList’: tcList = tyConOf (Proxy :: Proxy [])

But on GHC 8.0.1-rc1:

Foo.hs:9:19: error:                                                                                       
    • Expected kind ‘Proxy []’,                                                                           
        but ‘Data.Proxy.Proxy :: Proxy []’ has kind ‘Proxy []’                                            
    • In the first argument of ‘tyConOf’, namely ‘(Proxy :: Proxy [])’                                    
      In the expression: tyConOf (Proxy :: Proxy [])
      In an equation for ‘tcList’: tcList = tyConOf (Proxy :: Proxy [])

Change History (4)

comment:1 Changed 18 months ago by RyanGlScott

Cc: goldfire added

goldfire, I believe the kind equalities patch caused this, so I'm CC'ing you (specifically, it's msg5 that's causing this: http://git.haskell.org/ghc.git/blobdiff/6e56ac58a6905197412d58e32792a04a63b94d7e..6746549772c5cc0ac66c0fce562f297f4d4b80a2:/compiler/typecheck/TcErrors.hs).

comment:2 Changed 18 months ago by simonpj

Keywords: TypeInType added

comment:3 Changed 16 months ago by RyanGlScott

Resolution: fixed
Status: newclosed

Luckily, this seems to have been fixed. As of the time of writing, GHC 8.0 gives you the following error now:

$ /opt/ghc/8.0.1/bin/ghci
import DtGHCi, version 8.0.0.20160406: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/ryanglscott/.ghci
λ> import Data.Typeable
λ> tyConOf :: Typeable a => Proxy a -> TyCon; tyConOf = typeRepTyCon . typeRep
λ> tcList :: TyCon; tcList = tyConOf (Proxy :: Proxy [])

<interactive>:3:36: error:
    • Couldn't match type ‘* -> *’ with ‘*’
      Expected type: Proxy []
        Actual type: Proxy []
      Use -fprint-explicit-kinds to see the kind arguments
    • In the first argument of ‘tyConOf’, namely ‘(Proxy :: Proxy [])’
      In the expression: tyConOf (Proxy :: Proxy [])
      In an equation for ‘tcList’: tcList = tyConOf (Proxy :: Proxy [])
λ> :set -fprint-explicit-kinds 
λ> tcList :: TyCon; tcList = tyConOf (Proxy :: Proxy [])

<interactive>:5:36: error:
    • Couldn't match type ‘* -> *’ with ‘*’
      Expected type: Proxy * []
        Actual type: Proxy (* -> *) []
    • In the first argument of ‘tyConOf’, namely ‘(Proxy :: Proxy [])’
      In the expression: tyConOf (Proxy :: Proxy [])
      In an equation for ‘tcList’: tcList = tyConOf (Proxy :: Proxy [])

It even tells you about -fprint-explicit-kinds, which makes it abundantly clear that the error resulted from a kind mismatch. Hooray!

comment:4 Changed 8 months ago by bgamari

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.