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

#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

#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 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): The type you're passing to `foo` instantiates `t`. I think you want {{{#!hs baz = foo @(() -> Maybe String -> [()] -> IO ()) () (Just "baz") [()] }}} which works for me. Please close if you agree. Thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14286#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vagarenko): Silly me. Of course `foo () (Just "bar") [()] :: IO ()` means type of `foo` applied to 3 arguments is `IO ()` while `foo @(IO ())` means `foo` has no arguments. Sorry for the noise. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14286#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14286: Different behavior between type application and type annotation. -------------------------------------+------------------------------------- Reporter: vagarenko | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by vagarenko): * status: new => closed * resolution: => invalid -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14286#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC