Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!think.com!mintaka!spdcc!iecc!compilers-sender From: gateley@rice.edu (John Gateley) Newsgroups: comp.compilers Subject: Static type-checking with dynamic scoping Keywords: types, design Message-ID: <9101151731.AA01466@tone.rice.edu> Date: 15 Jan 91 17:31:17 GMT Sender: compilers-sender@iecc.cambridge.ma.us Reply-To: gateley@rice.edu (John Gateley) Organization: Compilers Central Lines: 33 Approved: compilers@iecc.cambridge.ma.us In-Reply-To: roberto@cernvax.cern.ch's message of 14 Jan 91 14:55:30 GMT 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 -- Send compilers articles to compilers@iecc.cambridge.ma.us or {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.