[GHC] #11675: Monomoprhic code makes ImpredicativeTypes infer an existential type

#11675: Monomoprhic code makes ImpredicativeTypes infer an existential type -------------------------------------+------------------------------------- Reporter: _deepfire | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1-rc2 (Type checker) | Keywords: | 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: -------------------------------------+------------------------------------- I realise that ImpredicativeTypes is a problematic extension, but I have found something that looks like an outright bug -- no polymorphism involved: {{{#!hs {-# LANGUAGE ImpredicativeTypes #-} module Foo where foo :: IO (Maybe Int) foo = do pure $ case undefined :: Maybe String of Nothing -> Nothing Just _ -> (undefined :: Maybe Int) }}} Produces the following errors: {{{ foo.hs:7:3: error: • Couldn't match type ‘forall a. Maybe a’ with ‘Maybe Int’ Expected type: IO (Maybe Int) Actual type: IO (forall a. Maybe a) • In a stmt of a 'do' block: pure $ case undefined :: Maybe String of { Nothing -> Nothing Just _ -> (undefined :: Maybe Int) } In the expression: do { pure $ case undefined :: Maybe String of { Nothing -> Nothing Just _ -> (undefined :: Maybe Int) } } In an equation for ‘foo’: foo = do { pure $ case undefined :: Maybe String of { Nothing -> Nothing Just _ -> (undefined :: Maybe Int) } } foo.hs:11:19: error: • Couldn't match type ‘a’ with ‘Int’ ‘a’ is a rigid type variable bound by a type expected by the context: forall a. Maybe a at foo.hs:11:19 Expected type: forall a. Maybe a Actual type: Maybe Int • In the expression: (undefined :: Maybe Int) In a case alternative: Just _ -> (undefined :: Maybe Int) In the second argument of ‘($)’, namely ‘case undefined :: Maybe String of { Nothing -> Nothing Just _ -> (undefined :: Maybe Int) }’ }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11675 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11675: Monomoprhic code makes ImpredicativeTypes infer an existential type -------------------------------------+------------------------------------- Reporter: _deepfire | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.1-rc2 checker) | Resolution: invalid | Keywords: 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: | -------------------------------------+------------------------------------- Changes (by goldfire): * status: new => closed * resolution: => invalid Comment: <snarky-joke>Yes, there is an outright bug: your module includes `{-# LANGUAGE ImpredicativeTypes #-}`.</snarky-joke> GHC's behavior is according to published typing rules, such as those in my recent [http://www.seas.upenn.edu/~sweirich/papers/esop2016-typeapp.pdf paper] on the subject. The problem is that nothing encourages GHC to instantiate the expression `Nothing` in your first case branch, and so GHC doesn't. If you add a type annotation there (or a visible type application) the problem should go away. (But I can't test this at the moment -- sorry.) It is regrettable that `ImpredicativeTypes` is not conservative over Haskell98, but the extension is known to be quite broken and is hopefully getting an overhaul soon. See ImpredicativePolymorphism. Thanks for reporting! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11675#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC