[GHC] #13893: Improved Help for Control.Concurrent and Control.Exception when "variable not in scope"

#13893: Improved Help for Control.Concurrent and Control.Exception when "variable not in scope" -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Poor/confusing Unknown/Multiple | error message Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The piece of code that bgamari wrote in {{{#13891}}} is interesting from the point of view of the error messages.\\ {{{ main = do putStrLn "forking" forkIO $ bracket (putStrLn "forked") (const $ putStrLn "finalize") (const $ putStrLn "hello" >> threadDelay 100000000) threadDelay 10000 putStrLn "done" }}} When the imports are not written GHC answers.\\ {{{ Prelude> :l testfork [1 of 1] Compiling Main ( testfork.hs, interpreted ) testfork.hs:6:5: error: Variable not in scope: forkIO :: t0 -> IO a0 testfork.hs:6:14: error: Variable not in scope: bracket :: IO () -> (b1 -> IO ()) -> (b0 -> IO b2) -> t0 testfork.hs:6:101: error: Variable not in scope: threadDelay :: Integer -> IO b2 testfork.hs:7:5: error: Variable not in scope: threadDelay :: Integer -> IO a1 Failed, modules loaded: none. Prelude> }}} It would be advisable to complete by:\\ {{{Perhaps you intended to import Control.Concurrent}}} for {{{forkIO}}} and {{{threadDelay}}}.\\ {{{Perhaps you intended to import Control.Exception}}} for {{{bracket}}}.\\ I hope you have a way to write it once for all the variables involved. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13893 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13893: Improved Help for Control.Concurrent and Control.Exception when "variable not in scope" -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vanto): Here I am talking about library that are natively in the compiler, of course, such as {{{Data.Char}}}. The principle would be identical to the suggestion of the pragmas to be used which are stated in the error message by the compiler.\\ This does not apply to library that are external to the compiler. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13893#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13893: Improved Help for Control.Concurrent and Control.Exception when "variable not in scope" -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: wontfix | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => wontfix Comment: As with #13883, I agree there is a problem here but don't believe the compiler is the right place to solve it. This is the exact sort of problem which you want external tooling to solve. Afterall, in the case of `cabal new-build` GHC doesn't even know of all of the packages available. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13893#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

don't believe the compiler is the right place to solve it\\ It is established that you do not know the Ada language compiler.\\ If you close this ticket, you do not correct anything and you forget. I reopen it even if you do not follow it, someone else later will take it into account for a more complete exploitation. I think your answer is an arbitrary answer. Often the answers of some of you that do not relate to a bug are arbitrary and seems to be controlled by anything other
#13893: Improved Help for Control.Concurrent and Control.Exception when "variable not in scope" -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by vanto): * status: closed => new * resolution: wontfix => Comment: than rational reason. You are forty people on the Committee, your opinion alone does not make law to close this ticket. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13893#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13893: Improved Help for Control.Concurrent and Control.Exception when "variable not in scope" -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by slyfox): * cc: slyfox (added) Comment: I have a few clarifying questions on this proposal. - Why take preference of packages coming with ghc in this case? It's not always the case that user wants to use '''base''''s primitives. I would say suggesting incorrect module imports would lead to more confusion. - Which procedure should define which packages (and modules) are blessed to deliver suggestions for symbols? For example, do '''xhtml''' or '''haskeline'' packages quialify as such? - As ticket's subject is worded why '''Control.Concurrent''' and '''Control.Exception''' should be threated special? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13893#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13893: Improved Help for Control.Concurrent and Control.Exception when "variable not in scope" -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vanto): Replying to [[span(style=color: #FF0000, slyfox )]]:\\
Why take preference of packages coming with ghc in this case?\\ Because these are the main libraries, of course. Those related to Haskell standard Prelude. (e.g Data.Char, Control.Applicative, Control.Monad, Data.Monoid, Data.Foldable and so on)\\\\
It's not always the case that user wants to use base's primitives.\\ so what?\\\\
I would say suggesting incorrect module imports would lead to more confusion.\\ You do not trust the compiler?\\ Dr. Bjarne Stroustrup said that you should always trust the answers given by the compiler. And he's right. So that GHC gives the right answers, you have to program it in this way. it is obvious.\\ If the compiler is able to recognize the variables that belong to a module ( which I quote above) it must be able to suggest the appropriate module.\\ __And to go further if the compiler is able to suggest the right module it must be able to compile it independently of the programmer.__\\ The compiler is able to recognize many of the leading pragmas (file-header LANGUAGE pragmas).
Which procedure should define which packages (and modules) are blessed to deliver suggestions for symbols?\\ I do not quite understand the question.\\ But if you talk about the code that makes it work it would be the same
As ticket's subject is worded why Control.Concurrent and Control.Exception should be threated special?\\ Not at all. These modules are examples. The subject is badly defined in
Experiencing yourself by writing a few expressions that need their pragmas to work, but do not write them and compile the file. You will be surprised to see how well the compiler is able to recognize them and to propose them to the programmer to insert them in the program. Even changes the order of the functions in the file. Moves the first function to the end for example and writes the function from end to beginning. Done with functions using various pragmas and you will be even more surprised.\\ __What the compiler can do is marvellous.__\\\\ procedure which defines the pragmas I suppose or another choice that remains to be defined.\\\\ the ticket. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13893#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13893: Improved Help for Control.Concurrent and Control.Exception when "variable not in scope" -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by slyfox): Replying to [comment:5 vanto]:
Replying to [[span(style=color: #FF0000, slyfox )]]:\\
Why take preference of packages coming with ghc in this case?\\ Because these are the main libraries, of course. Those related to Haskell standard Prelude. (e.g Data.Char, Control.Applicative, Control.Monad, Data.Monoid, Data.Foldable and so on)\\\\
These functions are not in haskell's (nor in GHC's) Prelude module. Otherwise you would get a working program instead of errors about missing symbols. Let's pick a simple example: **fromList**. Which module(s) should GHC suggest for these?
It's not always the case that user wants to use base's primitives.\\ so what?\\\\
I would say suggesting incorrect module imports would lead to more confusion.\\ You do not trust the compiler?\\ Dr. Bjarne Stroustrup said that you should always trust the answers given by the compiler. And he's right. So that GHC gives the right answers, you have to program it in this way. it is obvious.\\ If the compiler is able to recognize the variables that belong to a module ( which I quote above) it must be able to suggest the appropriate module.\\ __And to go further if the compiler is able to suggest the right module it must be able to compile it independently of the programmer.__\\ The compiler is able to recognize many of the leading pragmas (file-
It meas that suggestion will not be correct and will mislead user to add wrong module into imports instead of stating the fact about missing import. header LANGUAGE pragmas).
Experiencing yourself by writing a few expressions that need their
You will be surprised to see how well the compiler is able to recognize
pragmas to work, but do not write them and compile the file. them and to propose them to the programmer to insert them in the program.
Even changes the order of the functions in the file. Moves the first function to the end for example and writes the function from end to beginning. Done with functions using various pragmas and you will be even more surprised.\\ __What the compiler can do is marvellous.__\\\\
Which procedure should define which packages (and modules) are blessed to deliver suggestions for symbols?\\ I do not quite understand the question.\\ But if you talk about the code that makes it work it would be the same
As ticket's subject is worded why Control.Concurrent and Control.Exception should be threated special?\\ Not at all. These modules are examples. The subject is badly defined in
In order to earn user's trust compiler should have minimum of false positives. Missing LANGUAGE pragma detection works differently from symbol resolution. GHC already knows all the syntax it can parse. The lexer branches guarded by LANGUAGE pragmas have conditional code of either parsing expressions correctly or reporting an error about missing LANGUAGE pragma. Even that simple idea and implementation does not always work correctly due to language extensions having a syntactic overlap. procedure which defines the pragmas I suppose or another choice that remains to be defined.\\\\ LANGUAGE pragma detection does not require loading modules not used by the program. Suggesting symbols would require such loading. The question is about list of such autoloaded modules. the ticket. Please reword the ticket description. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13893#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13893: Improved help for "import" command at the start of a script when "variable not in scope" in error msg -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vanto): Replying to [[span(style=color: #FF0000, slyfox )]]\\ To make it simple: {{{ module Azer where -- import Data.Char main :: IO () main = print (map toLower "HELLO") }}} Compiler response:\\ {{{ Prelude> :l azer [1 of 1] Compiling Azer ( azer.hs, interpreted ) azer.hs:5:19: error: Variable not in scope: toLower :: Char -> b0 | 5 | main = print (map toLower "HELLO") | ^^^^^^^ Failed, modules loaded: none. }}} {{{toLower}}} belongs to data. Char. It would be easy for GHC to propose it in suggestion. How? I do not know. I have not the same knowledge as you in the Haskell compiler. Nevertheless I think that is possible. Easy or difficult to do, I don't know.\\ Regarding FromList, for instance:\\ {{{ Data.Sequence.fromList :: [a] -> Seq a -- Defined in `Data.Sequence' Data.IntSet.fromList :: [Key] -> IntSet -- Defined in `containers-0.5.7.1:Data.IntSet.Base' }}} It may be more difficult. We can teach the compiler to make a better difference.\\ How? I do not know yet but it can be studied.\\ This ticket should be considered as an idea for a future improvement in aid to the programmer.\\ Nevertheless as many people agree to improve the error messages, and this for a very long time, it is certainly better to start thinking about this. As this ticket is part of it, it will be de facto taken into account. Don't worry too much with this ticket, consider it only as an idea that can be applied later in the compiler. Do not close this ticket it will be able to serve later. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13893#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC