Opened 4 weeks ago

Closed 2 weeks ago

#13872 closed bug (duplicate)

Strange Typeable error message involving TypeInType

Reported by: RyanGlScott Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 8.0.1
Keywords: TypeInType, Typeable Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Poor/confusing error message Test Case:
Blocked By: Blocking:
Related Tickets: #13933 Differential Rev(s):
Wiki Page:

Description

I originally discovered this when tinkering with #13871. This program:

{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Foo where

import Data.Kind
import Data.Typeable

data Foo (a :: Type) (b :: Type) where
  MkFoo :: (a ~ Int, b ~ Char) => Foo a b

data family Sing (a :: k)
data SFoo (z :: Foo a b) where
  SMkFoo :: SFoo MkFoo

f :: String
f = show $ typeOf SMkFoo

Fails in GHC 8.0.1, 8.0.2, and 8.2 (after applying Phab:D3671) with a rather unsightly error message:

GHCi, version 8.3.20170624: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Foo              ( Foo.hs, interpreted )

Foo.hs:19:12: error:
    • No instance for (Typeable <>) arising from a use of ‘typeOf’
    • In the second argument of ‘($)’, namely ‘typeOf SMkFoo’
      In the expression: show $ typeOf SMkFoo
      In an equation for ‘f’: f = show $ typeOf SMkFoo
   |
19 | f = show $ typeOf SMkFoo
   |            ^^^^^^^^^^^^^

I'm not sure what this mysterious <> is, but I'm pretty sure it shouldn't be making an appearance here. (See also #13780, where <> also makes a surprise guest appearance.)

Change History (4)

comment:1 Changed 4 weeks ago by bgamari

<> is what the type pretty-printer calls Coercion types. AFAICT it's not entirely trivial making this Typeable, since the constructor's actual kind does indeed contain a coercion. I think I'll need to defer to Richard and Simon for what should be done about this in the future, however.

Last edited 4 weeks ago by bgamari (previous) (diff)

comment:2 Changed 4 weeks ago by RyanGlScott

To be clear: I'm not requesting that this datatype be an instance of Typeable, only that the error message be improved.

comment:3 Changed 4 weeks ago by bgamari

Ahhh, yes that is quite a reasonable request. Indeed it is quite poor.

comment:4 Changed 2 weeks ago by RyanGlScott

Resolution: duplicate
Status: newclosed

Closing in favor of #13933.

Note: See TracTickets for help on using tickets.