Output language of typechecking pass?
Benjamin Redelings
benjamin.redelings at gmail.com
Mon Nov 8 13:12:01 UTC 2021
Hi,
>> Questions:
>>
>> 1. It seems like this separation is actually necessary, in order to apply generalization only to let arguments written by the programmer, and not to let bindings introduced during desugaring. Is that right?
> I don't think so. That is, if we did it all in one pass, I still think we could get generalization right.
I guess I asked this question wrong. I mean to say, if we did the two
passes in the reverse order (desugaring first, followed by
typechecking), that would not work, right?
As the wiki says:
"This late desugaring is somewhat unusual. It is much more common to
desugar the program before typechecking, or renaming, because that
presents the renamer and typechecker with a much smaller language to
deal with. However, GHC's organisation means that
* error messages can display precisely the syntax that the user wrote; and
* desugaring is not required to preserve type-inference properties.
"
>> 2. Does the output of type checking contain type lambdas?
> Yes. See below.
>
>> 3. Does the type checking pass determine where to add dictionary arguments?
> Yes. See below.
>
>> 4. Are there any other resources I should be looking at?
> Yes. You want to enable -fprint-typechecker-elaboration (and possible -fprint-explicit-coercions). With the former, you get to see all this stuff you're looking for. It's normally suppressed so that the output resembles the user's code.
>
> I hope this helps!
> Richard
Hmm... so, I think I see how this works now. I don't think
'-fprint-explicit-coercions' does anything here though.
$ ghc -ddump-tc Test2.hs -fprint-typechecker-elaboration
...
AbsBinds [a_a2hp] [$dNum_a2hB]
{Exports: [g <= g_a2hz
wrap: <>]
Exported types: g :: forall a. Num a => a -> a -> a
[LclId]
Binds: g x_aYk y_aYl = (y_aYl * x_aYk) + 1
Evidence: [EvBinds{[W] $dNum_a2hs = $dNum_a2hq
[W] $dNum_a2hw = $dNum_a2hq
[W] $dNum_a2hq = $dNum_a2hB}]}
...
The type and dictionary arguments are visible here (along with the
evidence bindings), but type and dictionary applications are only
visible if you use -ddump-tc-ast, which is a lot more verbose. (I don't
think there is another flag that shows these applications?) Since I
didn't initially know what "evidence" was, and there is nothing to say
that a_a2hp is a type lambda argument, this was pretty opaque until I
managed to read the tc-ast and the light went on.
I can see now that the type and dictionary arguments are added by
annotating the AST.
Is there anywhere on the GHC wiki that explains how to interpret this
output, and says that the type and dictionary applications ARE there,
just not shown by '-ddump-tc'?
Perhaps it would be helpful to add some basic description of what comes
out of the typechecker to a page like this one? (below)
https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/hsc-main
-BenRI
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20211108/63e62340/attachment.html>
More information about the ghc-devs
mailing list