Commit 6c2b22ef authored by chak's avatar chak
Browse files

[project @ 2001-11-13 03:28:03 by chak]

A little more info about type checking
parent 2772264a
......@@ -11,6 +11,47 @@
Probably the most important phase in the frontend is the type checker,
which is located at <a
href="http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/compiler/typecheck/"><code>fptools/ghc/compiler/typecheck/</code>.</a>
GHC type checks programs in their original Haskell form before the
desugarer converts them into Core code. This complicates the type
checker as it has to handle the much more verbose Haskell AST, but it
improves error messages, as the those message are based on the same
structure that the user sees.
<p>
GHC defines the abstract syntax of Haskell programs in <a
href="http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/compiler/hsSyn/HsSyn.lhs"><code>HsSyn</code></a>
using a structure that abstracts over the concrete representation of
bound occurences of identifiers and patterns. The module <a
href="http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/compiler/typecheck/TcHsSyn.lhs"><code>TcHsSyn</code></a>
instantiates this structure for the type checker using <a
href="http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/compiler/typecheck/TcEnv.lhs"><code>TcEnv</code></a>.<code>TcId</code>
to represent identifiers - in fact, a <code>TcId</code> is currently
nothing but just a synonym for a <a href="vars.html">plain
<code>Id</code>.</a>
<h4>Types Variables and Zonking</h4>
<p>
During type checking type variables are represented by mutable variables
- cf. the <a href="vars.html#TyVar">variable story.</a> Consequently,
unification can instantiate type variables by updating those mutable
variables. This process of instantiation is (for reasons that elude
me) called <a
href="http://www.dictionary.com/cgi-bin/dict.pl?term=zonk&db=*">zonking</a>
in GHC's sources. The zonking routines for the various forms of Haskell
constructs are responsible for most of the code in the module <a
href="http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/compiler/typecheck/TcHsSyn.lhs"><code>TcHsSyn</code>,</a>
whereas the routines that actually operate on mutable types are defined
in <a
href="http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/compiler/typecheck/TcMType.lhs"><code>TcMTypes</code></a>;
this includes routines to create mutable structures and update them as
well as routines that check constraints, such as that type variables in
function signatures have not been instantiated during type checking.
The actual type unification routine is <code>uTys</code> in the same
module.
<p>
All type variables that may be instantiated (those in signatures
may not), but haven't been instantiated during type checking, are zonked
to <code>()</code>, so that after type checking all mutable variables
have been eliminated.
<h4>Type Checking Environment</h4>
<p>
......@@ -89,7 +130,7 @@
<p><small>
<!-- hhmts start -->
Last modified: Wed Aug 8 19:24:09 EST 2001
Last modified: Tue Nov 13 14:28:44 EST 2001
<!-- hhmts end -->
</small>
</body>
......
......@@ -74,8 +74,10 @@ data VarDetails
-- should not be unified with a non-tyvar type
</pre>
<a name="TyVar">
<h2>Type variables (<code>TyVar</code>)</h2>
</a>
<p>
The <code>TyVar</code> case is self-explanatory. The
<code>MutTyVar</code> case is used only during type checking. Then a
type variable can be unified, using an imperative update, with a type,
......@@ -224,7 +226,7 @@ A <code>Local</code> name can be cloned freely.
<!-- hhmts start -->
Last modified: Wed Aug 8 19:23:01 EST 2001
Last modified: Tue Nov 13 14:11:35 EST 2001
<!-- hhmts end -->
</small>
</body>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment