<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Thank you for the suggestions!</p>
<p>Setting the -fdefer-type-errors flag is indeed a good way to do
it (with also adding Opt_DeferTypedHoles and
Opt_DeferOutOfScopeVariables for other kind of errors).<br>
</p>
<p>Boldizsár<br>
</p>
<br>
<div class="moz-cite-prefix">2017.12.01. 4:12 keltezéssel,
Christopher Done Ãrta:<br>
</div>
<blockquote type="cite"
cite="mid:CAAJHNPBeCH+_QHfLUmBv8ZK1jfdbSYpPDwyGogrULRgwbpp-rw@mail.gmail.com">
<div>
<div dir="auto">I suppose setting -fdefer-type-errors would also
be handy in this scenario!</div>
<br>
<div class="gmail_quote">
<div>On Thu, 30 Nov 2017 at 15:37, Simon Peyton Jones via
ghc-devs <<a href="mailto:ghc-devs@haskell.org"
moz-do-not-send="true">ghc-devs@haskell.org</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">This
sounds like a good project!<br>
<br>
For the most part things look good:<br>
<br>
* Most type checker errors arise from *type constraints*.
The type checkder tries to solve these, but returns an
elaborated syntax tree (i.e. typechecked, and annotated with
types) even if constraint solving fails.<br>
<br>
* Some renamer errors are like this, notably out-of-scope
variables. (They just show up as another constraint.)<br>
<br>
However there is historical baggage. Back in the beginning,
most errors were treated by throwing an exception in the
typechecker monad; such exceptions can be caught, so that we
can get more than one error from the file, but no syntax
tree is returned. Example<br>
  let f = <expression> in <body><br>
If there was an error in <expression> we'd throw an
exception, catch it at the 'let', give 'f' the type<br>
  f :: forall a. a<br>
and continue to typecheck <body>.<br>
<br>
The trouble with the exception stuff is that you don't get
an elaborated syntax tree.<br>
<br>
So: I think you can get some of the way today, just by
returning the tree anyway even if there is an error to
report. But it'd take a bit more work to make more and more
errors into things that don't throw an exception. (Look for
failTc, failRn in thd code.)<br>
<br>
I'm not very familiar with the GHC API for this part, but
others will be. I'm certain it can be improved, so rather
than hacking around what is there already, do propose and
implement improvements.<br>
<br>
Simon<br>
<br>
 | -----Original Message-----<br>
| From: ghc-devs [mailto:<a
href="mailto:ghc-devs-bounces@haskell.org" target="_blank"
moz-do-not-send="true">ghc-devs-bounces@haskell.org</a>]
On Behalf Of Németh<br>
| Boldizsár<br>
| Sent: 30 November 2017 05:42<br>
| To: <a href="mailto:ghc-devs@haskell.org" target="_blank"
moz-do-not-send="true">ghc-devs@haskell.org</a><br>
| Subject: GHC typecheck API<br>
|<br>
| Dear GHC developers,<br>
|<br>
| I'm developing a framework for development tools for
Haskell. I use the<br>
| GHC API to parse and typecheck the source files. I
recently started to<br>
| work on a quick-fix (automatic program correction) for
Haskell source<br>
| code (correcting parenthesis problems, like 'putStrLn
"xxx" ++ show a'<br>
| ==> 'putStrLn ("xxx" ++ show a)'). To do that I need to
get the typed<br>
| syntax tree even if the program contains type or rename
errors. I could<br>
| only do this by a nasty hack, adding a new TH module
finalizer<br>
| (tcg_th_modfinalizers) to extract the type checker's state
before it<br>
| fails. Is there a "correct" way to do this? I would not
like this<br>
| refactorings to be unusable if the GHC API changes.<br>
|<br>
| By the way, if you know of any similar attempt please let
me know.<br>
|<br>
| Sincerely,<br>
| Boldizsár Németh<br>
| <a href="http://haskelltools.org" rel="noreferrer"
target="_blank" moz-do-not-send="true">haskelltools.org</a><br>
|<br>
| _______________________________________________<br>
| ghc-devs mailing list<br>
| <a href="mailto:ghc-devs@haskell.org" target="_blank"
moz-do-not-send="true">ghc-devs@haskell.org</a><br>
| <a
href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.hask"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.hask</a><br>
| <a href="http://ell.org" rel="noreferrer" target="_blank"
moz-do-not-send="true">ell.org</a>%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-<br>
| devs&data=02%7C01%7Csimonpj%<a
href="http://40microsoft.com" rel="noreferrer"
target="_blank" moz-do-not-send="true">40microsoft.com</a>%7C364b8db55e064415650d08d537b<br>
|
5323f%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636476173738772433&sda<br>
|
ta=Kf5rZYwht8ZGBtGNNH6Q44wLIeefxzHn2UfDIdrNNMU%3D&reserved=0<br>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank"
moz-do-not-send="true">ghc-devs@haskell.org</a><br>
<a
href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
</blockquote>
</div>
</div>
</blockquote>
<br>
</body>
</html>