Opened 4 years ago

Last modified 9 months ago

#10770 new bug

Typeable solver has strange effects

Reported by: NeilMitchell Owned by:
Priority: normal Milestone: 8.10.1
Component: Compiler (Type checker) Version: 7.10.1
Keywords: Typeable Cc: ndmitchell@…, ekmett
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case: typecheck/should_compile/T10770{a,b}
Blocked By: #5296 Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Given:

import Data.Typeable

main = print $ foo $ Just ()

foo :: Typeable (t a) => t a -> String
foo x = let k = show $ typeOf x in k

I get:

TypeableInfer.hs:7:24:
    Could not deduce (Typeable t) arising from a use of `typeOf'
    from the context (Typeable (t a))
      bound by the type signature for
                 foo :: Typeable (t a) => t a -> String
      at TypeableInfer.hs:6:8-38
    In the second argument of `($)', namely `typeOf x'
    In the expression: show $ typeOf x
    In an equation for `k': k = show $ typeOf x

However, the error goes away with the minor modification of:

foo x = show $ typeOf x

Change History (14)

comment:1 Changed 4 years ago by ekmett

Cc: ekmett added

comment:2 Changed 4 years ago by thomie

Component: CompilerCompiler (Type checker)

I get the same error with HEAD (ghc-7.11.20150809), and also notice the following:

Edit: new example that doesn't use Typeable.

{-# LANGUAGE FlexibleContexts #-}
module Test where

f :: (Show a, Show (Maybe a)) => Maybe a -> String
f x = let k = show x in k

g :: (Show a, Show (Maybe a)) => Maybe a -> String
g x = show x
Test.hs:4:6: warning:
    Redundant constraint: Show (Maybe a)
    In the type signature for:
         f :: (Show a, Show (Maybe a)) => Maybe a -> String

Test.hs:7:6: warning:
    Redundant constraint: Show a
    In the type signature for:
         g :: (Show a, Show (Maybe a)) => Maybe a -> String
Last edited 4 years ago by thomie (previous) (diff)

comment:3 Changed 4 years ago by goldfire

Milestone: 8.0.1

I have reason to believe that this will go away with visible type application (#5296). I'll add test cases to be sure.

comment:4 Changed 4 years ago by Richard Eisenberg <eir@…>

In d7f2ab0/ghc:

Test #10770

comment:5 Changed 4 years ago by goldfire

Blocked By: 5296 added
Owner: set to goldfire
Test Case: typecheck/should_compile/T10770{a,b}

comment:6 Changed 4 years ago by bgamari

Type of failure: None/UnknownGHC rejects valid program

Hmm, it seems that type application didn't resolve this. What is the status of this?

comment:7 Changed 4 years ago by bgamari

Milestone: 8.0.18.2.1

This bug won't be fixed in 8.0.1; bumping to 8.2.

comment:8 Changed 3 years ago by bgamari

Owner: changed from goldfire to bgamari

Given that I'm working on Typeable for 8.2 I'll take ownership of this.

comment:9 Changed 3 years ago by bgamari

Owner: bgamari deleted

Well, Typeable is merged and this is still an issue. I don't have time to look at this in the near future so I'll drop it.

comment:10 Changed 2 years ago by bgamari

Milestone: 8.2.18.4.1

Given that 8.2.1-rc1 is imminent, I'm bumping these off to the 8.4

comment:11 Changed 20 months ago by bgamari

Milestone: 8.4.18.6.1

This ticket won't be resolved in 8.4; remilestoning for 8.6. Do holler if you are affected by this or would otherwise like to work on it.

comment:12 Changed 16 months ago by RyanGlScott

Keywords: Typeable added

comment:13 Changed 15 months ago by bgamari

Milestone: 8.6.18.8.1

These won't be fixed for 8.6, bumping to 8.8.

comment:14 Changed 9 months ago by osa1

Milestone: 8.8.18.10.1

Bumping milestones of low-priority tickets.

Note: See TracTickets for help on using tickets.