🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #4679

Re: Static typing with Dynamic binding

#4679
From: willc
Date: Mon, 23 Feb 1987 20:04
92 lines
3615 bytes
In article <624@watcgl.UUCP> kdmoen@watcgl.UUCP (Doug Moen) writes:
>>This is the reason that dynamic scoping is incompatible with static type
>>checking.
>
>If anyone still believes this after reading this article, then they
>are invited to mail me an example of a DSP program
>that cannot be statically type checked.

What I believe is that dynamic scoping is incompatible with any reasonable
form of static type checking.  (Next time I'll be sure to include the
qualifiers.)  In practice I believe Moen's rules for DSP ("Dynamically
Scoped Pascal") reduce to the restriction previously characterized as
"bizarre" by Michael Condict:

    ...it is clear that a language cannot be dynamically bound and
    statically typed, unless you make the bizarre requirement a la
    FORTRAN that every variable named x must have the same type,
    even if they are otherwise completely unrelated.  Otherwise it
    is not computable whether a reference to variable x is referring
    to the x that was defined as an integer or the x that was defined
    somewhere else as a character string.

For example, here is a legal DSP program:

    program legal(modulo, my, imperfect, remembrance, of, Pascal);

    procedure a1;
      var x: integer;
      begin
        x := 10;
        writeln (x:20, glumpf (true))
      end;

    procedure a2;
      var x: integer;
      begin
        x := 11;
        writeln (x:20, glumpf (false))
      end;

    function glumpf (flag: boolean): integer;
      imports (x: integer);
      begin
        if flag then glumpf := foo(36) else glumpf := bar(37)
      end;

    function foo (n: integer): integer;
      imports (x: integer);
      begin
        foo := x + n
      end;

    function bar (n: integer): integer;
      begin
        bar := 49 * x
      end;

    begin
      a1;
      a2
    end.

If the definition of a2 is changed to

    procedure a2;
      var x: string;
      begin
        x := '49 * 37 = ';                /* if Pascal had strings */
        writeln (x, glumpf (false))
      end;

then the program ought to be legal but, according to Moen's rules for
DSP, it isn't.  (It would be legal if the name of the variable x declared
in a2 were changed to y.)  Moen's rules do not quite require that all
variables named x have the same type, but they come close.

> ....  If you tried to write a real program in DSP,
>then you would find that most procedures and functions would end up
>with rather long import lists.  

This would imply that most variables would indeed fall under the
restriction that variables of the same name must have the same type.

> .... But that's okay, because DSP exists
>solely to prove that it is possible for a statically typed, dynamically
>scoped language to exist.

Fair enough.  I think it should also be clear why such a language is
undesirable.

William Clinger
Tektronix Computer Research Lab
Technical Details
Message-ID: <1075@tekchips.TEK.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!sri-unix!hplabs!cae780!tektronix!tekcrl!tekchips!willc
References: <364@oracle.tc.fluke.COM> <814@unc.unc.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!sri-unix!hplabs!cae780!tektronix!tekcrl!tekchips!willc
From: willc@tekchips.UUCP
Newsgroups: comp.lang.misc
Subject: Re: Static typing with Dynamic binding
Message-ID: <1075@tekchips.TEK.COM>
Date: Mon, 23-Feb-87 15:04:55 EST
Article-I.D.: tekchips.1075
Posted: Mon Feb 23 15:04:55 1987
Date-Received: Thu, 26-Feb-87 23:47:51 EST
References: <364@oracle.tc.fluke.COM> <814@unc.unc.UUCP>
Reply-To: willc@tekchips.UUCP (Will Clinger)
Distribution: comp.lang.misc
Organization: Tektronix, Inc., Beaverton, OR.
Lines: 92