[GHC] #14286: Different behavior between type application and type annotation.

GHC ghc-devs at haskell.org
Wed Sep 27 10:44:18 UTC 2017


#14286: Different behavior between type application and type annotation.
-------------------------------------+-------------------------------------
           Reporter:  vagarenko      |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.2.1
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Consider this code:
 {{{#!hs
 {-# LANGUAGE FlexibleInstances, TypeApplications #-}

 module Bug where

 class Foo t where
   foo_ :: (IO () -> IO ()) -> t

 instance (Show a, Foo t) => Foo (a -> t) where
   foo_ k a = foo_ (\continue -> k (print a >> continue))

 instance Foo (IO ()) where
   foo_ k = k (return ())

 foo :: Foo t => t
 foo = foo_ id

 bar = foo () (Just "bar") [()] :: IO ()

 baz = foo @(IO ()) () (Just "baz") [()]
 }}}

 `bar` is accepted by GHC while `baz` is rejected:
 {{{
     * Couldn't match expected type `() -> Maybe [Char] -> [()] -> t'
                   with actual type `IO ()'
     * The function `foo' is applied to four arguments,
       but its type `IO ()' has none
       In the expression: foo @(IO ()) () (Just "baz") [()]
       In an equation for `baz': baz = foo @(IO ()) () (Just "baz") [()]
     * Relevant bindings include baz :: t (bound at bug.hs:19:1)
    |
 19 | baz = foo @(IO ()) () (Just "baz") [()]
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 }}}
 Why so?

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


More information about the ghc-tickets mailing list