[GHC] #7856: Wrong error message for unknown Instance

#7856: Wrong error message for unknown Instance ----------------------------------------------+----------------------------- Reporter: bas | Owner: Type: feature request | Status: new Priority: normal | Component: Compiler (Type checker) Version: 7.6.3 | Keywords: Instance Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Incorrect warning at compile-time | Blockedby: Blocking: | Related: ----------------------------------------------+----------------------------- This type-incorrect program gives a wrong error message: {{{ main = tmp "hello" where tmp :: String -> IO () tmp = sequence_ lst lst = [putStrLn "hi"] }}} Namely: {{{ Couldn't match expected type `IO ()' with actual type `()' Expected type: String -> IO () Actual type: String -> () In the return type of a call of `sequence_' In the expression: sequence_ lst }}} I would not expect the "actual type" to be "String -> ()", but rather "IO ()". Note: GHC expects that "(->) String" is a monad. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7856 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7856: Wrong error message for unknown Instance ----------------------------------------+----------------------------------- Reporter: bas | Owner: Type: feature request | Status: new Priority: normal | Milestone: _|_ Component: Compiler (Type checker) | Version: 7.6.3 Keywords: Instance | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Incorrect warning at compile-time Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ----------------------------------------+----------------------------------- Changes (by simonpj): * difficulty: => Unknown * milestone: => _|_ Comment: Here is what is happening. We typecheck this definition {{{ tmp :: String -> IO () tmp = sequence_ lst where lst = [putStrLn "hi"] }}} Remember that `sequence_ :: Monad m => [m a] -> m ()`. So GHC generates two type equalities: {{{ (1) m () ~ (->) String (IO ()) -- From the return type of (sequence_ lst) (2) m a ~ IO () -- From the argument of _sequence }}} If GHC solved (2) first (by `m:=IO, a:=()`), all would be well. But it happens to try to solve (1) first, by decomposing into {{{ (1a) m ~ (->) String (1b) () ~ IO () }}} And it is (1b) that is reported as an error. In reporting the error GHC says where it came from, namely from (1), that is unifying `m () ~ String -> IO ()`. But by that time GHC has solved (1b) by `m:=(->) String`, so the error is reported as a mismatch between `String -> ()` and `String -> IO ()`. So that's the reason. And I don't see an easy way to improve matters. Maybe we should somehow seek to prioritise (2) over (1), but how? Nice example. Simon -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7856#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7856: Wrong error message for unknown Instance ------------------------------------------------+--------------------------- Reporter: bas | Owner: Type: feature request | Status: closed Priority: normal | Milestone: _|_ Component: Compiler (Type checker) | Version: 7.6.3 Resolution: invalid | Keywords: Instance Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Incorrect warning at compile-time | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: ------------------------------------------------+--------------------------- Changes (by monoidal): * status: new => closed * resolution: => invalid Comment:
I would not expect the "actual type" to be "String -> ()", but rather "IO ()".
You do get "IO ()", at least on 7.6.2 and HEAD: {{{ Couldn't match expected type ‛String -> IO ()’ with actual type ‛IO ()’ In the return type of a call of ‛sequence_’ Probable cause: ‛sequence_’ is applied to too many arguments In the expression: sequence_ lst In an equation for ‛tmp’: tmp = sequence_ lst }}} Given {{{tmp :: String -> IO (); tmp = sequence_ lst}}} the error message is clear: `sequence_ lst` is `IO ()` while the signature is `String -> IO ()`. I'm closing the ticket, but please reopen if you disagree. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7856#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7856: Wrong error message for unknown Instance ------------------------------------------------+--------------------------- Reporter: bas | Owner: Type: feature request | Status: closed Priority: normal | Milestone: _|_ Component: Compiler (Type checker) | Version: 7.6.3 Resolution: invalid | Keywords: Instance Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Incorrect warning at compile-time | Difficulty: Unknown Testcase: typecheck/should_fail/T7856 | Blockedby: Blocking: | Related: ------------------------------------------------+--------------------------- Changes (by simonpj): * testcase: => typecheck/should_fail/T7856 -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7856#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC