<div dir="ltr"><div>I wondered if <a href="https://downloads.haskell.org/~ghc/7.8.1/docs/html/users_guide/defer-type-errors.html">https://downloads.haskell.org/~ghc/7.8.1/docs/html/users_guide/defer-type-errors.html</a> could help.<br><br></div>I tried to click around in the GHC 8.2 tree of <a href="http://stuff.codereview.me/ghc/#ghc/compiler/typecheck/TcErrors.hs?corpus=ghc-8.2.1-rc2&signature&line=120">http://stuff.codereview.me/ghc/#ghc/compiler/typecheck/TcErrors.hs?corpus=ghc-8.2.1-rc2&signature&line=120</a>, but it seems deferring type errors just reports via a different means, and doesn't change the type-checking behavior. But correct me if I'm wrong.<br></div><div class="gmail_extra"><br><div class="gmail_quote">2018-03-05 17:11 GMT+01:00 Simon Peyton Jones via ghc-devs <span dir="ltr"><<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div link="blue" vlink="purple" lang="EN-GB">
<div class="m_272964852394899002WordSection1">
<p class="MsoNormal"><span style="font-size:12.0pt">Always cc ghc-devs! Bottle-necking on me may well yield a slow response! Or even Haskell-café.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">What is the type of (\x -> [x,y])? Where y is in scope with type y::a. Presumably something like a -> [a]? Or is it forall a. a -> [a]? And would your answer change if you had just (\x -> [x,x])?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Generalisation is tricky, and for terms with non-closed types it is hard to know what you need in your use-case. A type like ‘a’ might be a very fine answer!<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">A lot depends on precisely what you are trying to do.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Simon<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><u></u> <u></u></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> Peter Podlovics [mailto:<a href="mailto:peter.d.podlovics@gmail.com" target="_blank">peter.d.podlovics@<wbr>gmail.com</a>]
<br>
<b>Sent:</b> 05 March 2018 14:54<br>
<b>To:</b> Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>><br>
<b>Subject:</b> Re: Type checking expressions<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm">
My main concern with that approach is that it might not give the correct type. For example the hsPatType function only gives unconstrained types, so it is incorrect for any numeric literal, since it gives "a" instead of "Num a => a".
<br>
<br>
So the question is whether it is possible to retrieve the context of the type variables as well. Also this problem may arise in the case of expressions as well, that is why I scrapped that approach and tried to type check the AST with the TcM monad directly,
but without any success.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm">
Could you give me any leads on how to solve this problem?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Thanks in advance,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Peter<u></u><u></u></p>
</div>
</div><div><div class="h5">
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
On Mon, Mar 5, 2018 at 9:44 AM, Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">Peter</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36.0pt">
<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:36.0pt">
My goal is to determine the type of every expression, pattern etc. in the<br>
syntax tree<span style="font-size:12.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt">After type checking is complete, the syntax tree is liberally annotated with types.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt">We do not yet have a function</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt"> hsExprType :: HsExpr Id -> Type</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt">but we do have</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt"> TcHsTyn.hsPatType :: Pat GhcTc -> Type</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt">and you or someone could readily make an equivalent for HsExpr.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Most type errors are reported by adding an error constraint, but still returning an annotated tree.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Some, I’m afraid, are still done in the old way, by throwing an exception – so you don’t get back an annotated tree in that case. But they are relatively
rare.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Others must have wanted something like this…</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Simon</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><u></u><u></u></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> ghc-devs [mailto:<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@<wbr>haskell.org</a>]
<b>On Behalf Of </b>Peter Podlovics<br>
<b>Sent:</b> 02 March 2018 12:05<br>
<b>To:</b> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<b>Subject:</b> Fwd: Type checking expressions</span><u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Hello everyone,<br>
<br>
I would like to ask for some advice regarding the type checker part of GHC.<br>
My goal is to determine the type of every expression, pattern etc. in the<br>
syntax tree. Currently the compiler doesn't store this information, so I have<br>
to type check manually. One important aspect is that the program may be ill-typed,<br>
but I still want to extract as much information as possible.<br>
<br>
I tried using local type checking functions (eg.: tcInferSigma), but whenever<br>
I used it on an expression that had some "out-of-scope" names in it, it failed.<br>
<br>
> f xs = length xs<br>
<br>
The reason was that xs was not in the local environment.<br>
<br>
My question is: how could I provide the necessary local environment for these<br>
type checking functions? Also in the general case, is it possible to somehow<br>
annotate each expression with its type during the type checking?<br>
<br>
The motivation for this is that I want to implement a tool that automatically<br>
corrects ill-typed programs based heuristics. For that I need to know the types<br>
of certain AST nodes.<span style="color:#888888"><br>
<br>
<span class="m_272964852394899002m-7452985673952537534hoenzb">Peter Podlovics</span></span><u></u><u></u></p>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:6.0pt"> <u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div></div></div>
</div>
</div>
<br>______________________________<wbr>_________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/ghc-devs</a><br>
<br></blockquote></div><br></div>