Static type-checking with dynamic scoping

gateley@rice.edu (John Gateley)
Tue, 15 Jan 91 11:31:17 CST

          From comp.compilers

Related articles
Static type-checking with dynamic scoping roberto@cernvax.cern.ch (1991-01-14)
Static type-checking with dynamic scoping gateley@rice.edu (1991-01-15)
Re: Static type-checking with dynamic scoping Chuck_Lins.SIAC_QMAIL@gateway.qm.apple.com (Chuck Lins) (1991-01-15)
Re: Static type-checking with dynamic scoping brm@Neon.Stanford.EDU (Brian R. Murphy) (1991-01-15)
Re: Static type-checking with dynamic scoping barmar@think.com (1991-01-16)
Re: Static type-checking with dynamic scoping brm@Neon.Stanford.EDU (Brian R. Murphy) (1991-01-17)
Re: Static type-checking with dynamic scoping mac@eleazar.dartmouth.edu (1991-01-21)
| List of all articles for this month |

Newsgroups: comp.compilers
From: gateley@rice.edu (John Gateley)
In-Reply-To: roberto@cernvax.cern.ch's message of 14 Jan 91 14:55:30 GMT
Keywords: types, design
Organization: Compilers Central
Date: Tue, 15 Jan 91 11:31:17 CST

Is it possible to do static type checking with dynamic scoping?


Well, not really. Consider the following program:


procedure foo (x:int) ...;


procedure bar (x:string) ...;


procedure baz (...) ... x ...;


What type will baz's x have, int or string? One solution that may be
possible is to construct the call graph and make sure that all bindings of x
which reach a given use have the same type. There are some drawbacks to this
solution - it is a "whole program" strategy, separate compilation is not
allowed (without lots of work). It also cannot correctly type check some
programs which are nevertheless legal. For example, the use in baz may be
limited to the x:string binding, but the call graph (constructed at compile
time) may reflect a call from foo which is never taken.


A more restrictive solution is to treat variables as global - assign them
types at the global level. Then all bindings of the variable has to match
that type.


One thing that really messes life up is 1st-class functions. They make the
call graph impossible to construct at compile time.


Are you sure you really want dynamic binding?


John
gateley@rice.edu
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.