Python from Wise Guy's Viewpoint

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dirk Thierbach

    Re: Python from Wise Guy's Viewpoint

    prunesquallor@c omcast.net wrote:[color=blue]
    > Dirk Thierbach <dthierbach@gmx .de> writes:[/color]
    [color=blue]
    > As I mentioned earlier in this thread, the two things I object to in a
    > static type system are these:
    >
    > 1) The rejection of code I know to be useful, yet the system is
    > unable to prove correct.
    >
    > 2) The requirement that I decorate my program with type
    > information to give the type checker hints to enable it
    > to check things that are, to me, obviously correct.[/color]

    Yes. I have also said it earlier, but (1) is nearly never going to
    happen (if you substitute "correct" with "type correct", and for a
    suitable definition of useful), and you don't have to do (2) if there
    is type inference.
    [color=blue]
    > Being unable to prove code correct is the same thing as being able to
    > prove it incorrect. This makes three classes of code:
    >
    > 1) provably type safe for all inputs
    > 2) provably erroneous for all inputs
    > 3) neither of the above
    >
    > Both dynamic and static type systems behave the same way for classes 1
    > and 2 except that static systems reject the code in section 2 upon
    > compilation while dynamic systems reject it upon execution. It is
    > section 3 that is under debate.[/color]
    [color=blue]
    > Those of us that are suspicious of static typing believe that there
    > are a large enough number of class 3 programs that they will be
    > regularly or frequently encountered.[/color]

    Yep. The static typers believe (from experience) that there is a very
    small number of class 3 programs, and usually all programs you
    normally write fall into class 1. They also know that this is not true
    for all static type systems. For languages with a lousy static type
    system, there is a large number of class 3 programs, where you have to
    cheat to convince the type checker that they are really type safe. The
    static typers also believe that with a good static type system, all
    useful class 3 programs can be changed just a little bit so they fall
    into class 1. In this process, they will become better in almost all
    cases (for a suitable definition of "better").
    [color=blue]
    > We believe that a large number of these class 3 programs will have
    > inputs that cannot be decided by a static type checker but are
    > nonetheless `obviously' correct. (By obvious I mean fairly apparent
    > with perhaps a little thought, but certainly nothing so convoluted
    > as to require serious reasoning.)[/color]

    Why do you believe this? A HM type checker doesn't do anything but
    automate this "obvious" reasoning (in a restricted field), and points
    out any errors you might have made (after all, humans make errors).
    [color=blue]
    > Static type check aficionados seem to believe that the number of class
    > 3 programs is vanishingly small and they are encountered rarely. They
    > appear to believe that any program that is `obviously' correct can be
    > shown to be correct by a static type checking system. Conversely,
    > they seem to believe that programs that a static type checker find
    > undecidable will be extraordinarily convoluted and contrived, or
    > simply useless curiosities.[/color]

    Yes.
    [color=blue]
    > No one has offered any empirical evidence one way or another, but the
    > static type people have said `if class 3 programs are so ubiquitous,
    > then it should be easy to demonstrate one'. I'll buy that. Some of
    > the people in here have offered programs that take user input as an
    > example. No sane person claims to read the future, so any statically
    > typed check program would have to perform a runtime check.[/color]

    Yes, and that's what it does. No problem.
    [color=blue]
    > I (and Don Geddis) happen to believe that there are a huge number of
    > perfectly normal, boring, pedestrian programs that will stymie a
    > static type checker. I've been offering a few that I hope are small
    > enough to illustrate the problem and not so contrived as to fall into
    > the `pointless' class.
    >
    > The first program I wrote (a CPS lookup routine) generally confuses
    > wimp-ass static type checking like in Java.
    >
    > Stephan Bevan showed that SML/NJ had no problem showing it was type
    > safe without giving a single type declaration. I find this to be
    > very cool.[/color]

    Good.
    [color=blue]
    > I offered my `black hole' program and got these responses:[/color]
    [...][color=blue]
    > Will this the response for any program that does, in fact, fool a
    > number of static type checkers?[/color]

    No. You have also been shown that it can check statically both in
    Haskell and OCaml. (I cannot think of any way to make it pass
    in C++ or Java, but that's to be expected.)
    [color=blue]
    > This appears to be getting very close to arguing that static type
    > checkers never reject useful programs because, by definition, a
    > program rejected by a static type checker is useless.[/color]

    It may not be useless, but you will definitely need to think about
    it. And if it is useful, in nearly all cases you can make a little
    change or express it a little differently, and it will check.
    [color=blue]
    > Another one was a CPS routine that traverses two trees in a lazy
    > manner and determins if they have the same fringe. The point was not
    > to find out if this could be done in SML or Haskell. I know it can.
    > The point was to find out if the static type checker could determine
    > the type safety of the program.
    > There is a deliberate reason I did not create a `lazy cons'
    > abstraction. I wanted to see if the type checker, with no help
    > whatsover, could determine that the type of the lambda abstractions
    > that are *implementing* the lazy consing.[/color]

    See below for "lazy cons".
    [color=blue]
    > Re-writing the program in C++ with huge amounts of type decorations
    > and eliminating the lambdas by introducing parameterized classes does
    > not demonstrate the power of static type checking.[/color]

    No, it doesn't. That was just Brian saying "it's so easy, I'll
    do it the hard way and demonstrate that it can even be done with
    a lousy static type system as in C++".
    [color=blue]
    > Re-writing the program in a lazy language also does nothing to
    > demonstrate the power of static type checking.[/color]

    May I suggest that you try it yourself? It might be a good way to
    get some experience with OCaml, though for a beginner it might take
    some time to get used to the syntax etc. Pure lambda terms are the
    same in every functional language, after all.

    The only issue is that one should use datatypes for recursive
    structures, i.e. one would normally use a 'lazy cons' abstraction
    (which would be the natural thing to do anyway). In OCaml, you can get
    around this with -rectypes (someone has already demonstrated how to do
    lazy lists in this way). In Haskell you would need them, but since
    Haskell is already lazy, that's probably not the point.

    So yes, for recursive types you need to give the type checker "a
    little hint", if you want to put it that way. But that's done on
    purpose, because it is the natural way to do it, and it is note done
    because it would be impossible to statically check such terms.

    So if you are extremely picky, and if you refuse to do the "lazy cons"
    initially and consider command line options cheating, that's one of
    the programs of class 3 that can be put into class 1 by making a
    little change, where this change turns out to make your program better
    to understand in the first place. Is this so bad that you want to stay
    clear from static typing at any price?

    (I bet someone will now comment on that ignoring the "extremely picky"
    part :-( .)

    - Dirk


    Comment

    • Dirk Thierbach

      Re: Python from Wise Guy's Viewpoint

      Pascal Costanza <costanza@web.d e> wrote:[color=blue]
      > Dirk Thierbach wrote:[/color]
      [color=blue][color=green]
      >> Maybe. It sure would help if you'd tell me your view instead of having
      >> me guess :-) For me, a type is a certain class of values, and a static
      >> type is given by a limited language describing such classes. A
      >> dynamic type is a tag that is associated with a value. Arbitrary
      >> classes of values (like "all reals less than 200") are not a type.[/color]
      >
      > What are "non-arbitrary classes of values"?[/color]

      Those that can be described by the language available for static types
      e.g. in Haskell or OCaml.
      [color=blue]
      > According to your criteria, (real * 200) is
      > - a certain class of values
      > - given in a limited language describing that class[/color]

      Yes, but you will have a hard time developing a static type checker
      that will work with such a language.
      [color=blue]
      > I would be interesting to see a convincing definition of the term "type"
      > that precludes (real * 200), and similar type specifications.[/color]

      Look at the definition for type in Haskell or OCaml, for example.
      [color=blue]
      > (Maybe it helps to explain that CHECK-TYPE doesn't check a value per se.
      > (check-type 5 (real * 200)) doesn't work. CHECK-TYPE checks a property
      > of the variable it is being passed.)[/color]

      Yes, I know. What does that explain?
      [color=blue]
      > "very rare situations"
      > "never a show-stopper"
      >
      > How do you know?
      >
      > If you are only talking about your personal experiences, that's fine,
      > but you should say so.[/color]

      Of course I am talking from personal experience, like everyone does.
      There is not other way. But in this case, I think my experience is
      sufficient to say that.
      [color=blue]
      > The only claim I make is that static type systems need to reject
      > well-behaved programs. That's an objective truth.[/color]

      This depends on the definition of "well-behaved". The claim I make is
      that for a suitable definition of "well-behaved", it is not an
      objective truth. And even if you stick to your definition of
      "well-behaved", it doesn't really matter in practice.
      [color=blue]
      > All I hear is that you (and many others) say that the disadvantages
      > of static typing are negligible. However, I haven't found any
      > convincing arguments for that claim.[/color]

      What kind of arguments would you like to have? I have tried to
      show with a few examples that even programs that you think should
      be rejected with static typing will be accepted (if you allow for
      the fact that they are written in a different language).

      What else is there I could possibly do? The simplest way is probably
      that you just sit down and give it a try. No amount of talking can
      replace personal experience. Get Haskell or OCaml and do a few simple
      examples. You will find that they have many things that you won't
      like, e.g. no good IDE, no "eval", and (as every language) they
      require a slightly different mindset compared to what you're used
      to. They might also not have the library functions that you are used
      to. But it might give you a good idea what programs are statically
      typeable and what are not.
      [color=blue]
      > But I am interested in the question why you (or others) think that
      > almost all software should be developed like that.[/color]

      I didn't say that. Please do not put up a strawman. In fact, I
      explicitely said "you use whatever tool you like best".
      [color=blue]
      > I have chosen to illustrate examples in which a dynamic approach might
      > be considerably better.[/color]

      And you didn't convince me; all your examples can be statically
      typed.
      [color=blue]
      > Again, to make this absolutely clear, it is my personal experience
      > that dynamic type checking is in many situations superior to static
      > type checking.[/color]

      That's maybe the important point. HOW DO YOU KNOW IF YOU HAVE NEVER
      TRIED IT? (In a language with good static typing, not in a language
      with lousy static typing). And obviously you haven't tried it,
      otherwise you wouldn't give examples that can be easily statically
      typed, or confuse exceptions or dynamic checks with static type checks.
      So it cannot come from your personal experience.
      [color=blue]
      > But I don't ask anyone to unconditionally use dynamically typed
      > languages.[/color]

      But you insist that dynamically typed languages are "better" or
      "superior to" statically typed, because you claim you cannot do things
      in a statically typed language that you can do in a dynamically typed
      one. That's the point where I disagree. I don't ask you to use a
      statically typed language, I just want you to give admit that both
      are equally good in this respect, or at least you should sit down and
      verify that yourself before saying it.

      - Dirk

      Comment

      • Ed Avis

        Re: Python from Wise Guy's Viewpoint

        Pascal Costanza <costanza@web.d e> writes:
        [color=blue][color=green]
        >>Should we then conclude that compile-time syntax checking is not
        >>worth having?[/color]
        >
        >No. Syntax errors make the program fail, regardless whether this is
        >checked at compile-time or at runtime.
        >
        >A type "error" detected at compile-time doesn't imply that the
        >program will fail.[/color]

        Actually it does, in a statically typed language. If you write a
        function which expects a Boolean and you pass it a string instead,
        it's going to fail one way or another.

        OK, the bad call of that function might never be reachable in actual
        execution, but equally the syntax error in Tcl code might not be
        reached. I'd rather find out about both kinds of mistake sooner
        rather than later.

        (I do mean a type error and not a type 'error' - obviously if you have
        some mechanism to catch exceptions caused by passing the wrong type,
        you wouldn't want this to be checked at compile time.)

        --
        Ed Avis <ed@membled.com >

        Comment

        • Matthias Blume

          Re: Python from Wise Guy's Viewpoint

          Ed Avis <ed@membled.com > writes:
          [color=blue]
          > Pascal Costanza <costanza@web.d e> writes:
          >[color=green][color=darkred]
          > >>Should we then conclude that compile-time syntax checking is not
          > >>worth having?[/color]
          > >
          > >No. Syntax errors make the program fail, regardless whether this is
          > >checked at compile-time or at runtime.
          > >
          > >A type "error" detected at compile-time doesn't imply that the
          > >program will fail.[/color]
          >
          > Actually it does, in a statically typed language.[/color]

          Nitpick: Neither syntactic nor statically checked type errors make
          programs fail. Instead, their presence simply implies the absence of a
          program. No program, no program failing...

          Matthias

          Comment

          • Pascal Costanza

            Re: Python from Wise Guy's Viewpoint

            Dirk Thierbach wrote:[color=blue]
            > Pascal Costanza <costanza@web.d e> wrote:
            >[color=green]
            >>Dirk Thierbach wrote:[/color]
            >
            >[color=green][color=darkred]
            >>>Maybe. It sure would help if you'd tell me your view instead of having
            >>>me guess :-) For me, a type is a certain class of values, and a static
            >>>type is given by a limited language describing such classes. A
            >>>dynamic type is a tag that is associated with a value. Arbitrary
            >>>classes of values (like "all reals less than 200") are not a type.[/color]
            >>
            >>What are "non-arbitrary classes of values"?[/color]
            >
            > Those that can be described by the language available for static types
            > e.g. in Haskell or OCaml.[/color]

            This sounds like a circular definiton.
            [color=blue][color=green]
            >>According to your criteria, (real * 200) is
            >>- a certain class of values
            >>- given in a limited language describing that class[/color]
            >
            > Yes, but you will have a hard time developing a static type checker
            > that will work with such a language.[/color]

            I am not asking for a definition of the term "static type", but for a
            definition of the term "type".
            [color=blue][color=green]
            >>I would be interesting to see a convincing definition of the term "type"
            >>that precludes (real * 200), and similar type specifications.[/color]
            >
            > Look at the definition for type in Haskell or OCaml, for example.[/color]

            Haskell: "An expression evaluates to a value and has a static type."
            (http://www.haskell.org/onlinereport/intro.html#sect1.3 )

            Where is the definiton for "type"? (without "static"?)

            I haven't found a definiton in http://caml.inria.fr/ocaml/htmlman/index.html
            [color=blue][color=green]
            >>(Maybe it helps to explain that CHECK-TYPE doesn't check a value per se.
            >>(check-type 5 (real * 200)) doesn't work. CHECK-TYPE checks a property
            >>of the variable it is being passed.)[/color]
            >
            > Yes, I know. What does that explain?[/color]

            Let's first get our terminology right.
            [color=blue][color=green]
            >>The only claim I make is that static type systems need to reject
            >>well-behaved programs. That's an objective truth.[/color]
            >
            > This depends on the definition of "well-behaved". The claim I make is
            > that for a suitable definition of "well-behaved", it is not an
            > objective truth. And even if you stick to your definition of
            > "well-behaved", it doesn't really matter in practice.[/color]

            "well-behaved" means "doesn't show malformed behavior at runtime", i.e.
            especially "doesn't core dump".

            "Behavior" is a term that describes dynamic processes. I am only
            interested in dynamic behavior here.

            I don't mind if you want to change that terminology. Let's just rephrase
            it: Static type systems need to reject programs that wouldn't
            necessarily fail in serious ways at runtime.
            [color=blue][color=green]
            >>All I hear is that you (and many others) say that the disadvantages
            >>of static typing are negligible. However, I haven't found any
            >>convincing arguments for that claim.[/color]
            >
            > What kind of arguments would you like to have? I have tried to
            > show with a few examples that even programs that you think should
            > be rejected with static typing will be accepted (if you allow for
            > the fact that they are written in a different language).[/color]

            Yes, for some of them.
            [color=blue][color=green]
            >>But I am interested in the question why you (or others) think that
            >>almost all software should be developed like that.[/color]
            >
            > I didn't say that. Please do not put up a strawman. In fact, I
            > explicitely said "you use whatever tool you like best".[/color]

            But that was the original question that initiated this thread. If we
            have an agreement here, that's perfect!
            [color=blue][color=green]
            >>I have chosen to illustrate examples in which a dynamic approach might
            >>be considerably better.[/color]
            >
            > And you didn't convince me; all your examples can be statically
            > typed.[/color]

            What about the example in

            ?

            I don't think this can be done without a serious rewrite.
            [color=blue][color=green]
            >>Again, to make this absolutely clear, it is my personal experience
            >>that dynamic type checking is in many situations superior to static
            >>type checking.[/color]
            >
            > That's maybe the important point. HOW DO YOU KNOW IF YOU HAVE NEVER
            > TRIED IT? (In a language with good static typing, not in a language
            > with lousy static typing). And obviously you haven't tried it,
            > otherwise you wouldn't give examples that can be easily statically
            > typed, or confuse exceptions or dynamic checks with static type checks.
            > So it cannot come from your personal experience.[/color]

            Right, it comes from a more principled consideration: You can't have
            metacircularity in a statically type language. You might be able to have
            metacircularity if you strictly separate the stages, but as soon as you
            want to be able to at least occasionally call base code from meta code
            and vice versa, then you lose.

            Metacircularity gives me the guaranntee that I can always code around
            any unforeseeable limitations that might come up, without having to
            start from scratch.

            So, yes, I am interested in having the opportunity to change invariants
            during the runtime of a program. This might sound self-contradictory,
            but in practice it isn't. Remember, "One man's constant is another man's
            variable." (see http://www-2.cs.cmu.edu/afs/cs.cmu.e...sd/perlis.html )
            [color=blue][color=green]
            >>But I don't ask anyone to unconditionally use dynamically typed
            >>languages.[/color]
            >
            > But you insist that dynamically typed languages are "better" or
            > "superior to" statically typed, because you claim you cannot do things
            > in a statically typed language that you can do in a dynamically typed
            > one. That's the point where I disagree. I don't ask you to use a
            > statically typed language, I just want you to give admit that both
            > are equally good in this respect, or at least you should sit down and
            > verify that yourself before saying it.[/color]

            I haven't said that I can do more things in a dynamically typed
            language. I have said that statically typed languages need to reject
            well-behaved programs. That's a different claim. We are not talking
            about Turing equivalence.

            If a base program calls its meta program and changes types, you can't
            type check such a program by definition.

            For example:

            (defun check (x)
            (integerp x))

            (defun example-1 ()
            (let ((x 5))
            (assert (check x))
            (print 'succeeded)
            (eval '(defun check (x)
            (stringp x)))))

            Now, this might seem nonsensical, but consider this:

            (defun example-2 ()
            (eval '(defun check (x)
            (realp x)))
            (example-1))



            Pascal

            --
            Pascal Costanza University of Bonn
            mailto:costanza @web.de Institute of Computer Science III
            http://www.pascalcostanza.de Römerstr. 164, D-53117 Bonn (Germany)

            Comment

            • Pascal Costanza

              Re: Python from Wise Guy's Viewpoint

              Ed Avis wrote:[color=blue]
              > Pascal Costanza <costanza@web.d e> writes:
              >
              >[color=green][color=darkred]
              >>>Should we then conclude that compile-time syntax checking is not
              >>>worth having?[/color]
              >>
              >>No. Syntax errors make the program fail, regardless whether this is
              >>checked at compile-time or at runtime.
              >>
              >>A type "error" detected at compile-time doesn't imply that the
              >>program will fail.[/color]
              >
              > Actually it does, in a statically typed language.[/color]

              No, it doesn't.
              [color=blue]
              > If you write a
              > function which expects a Boolean and you pass it a string instead,
              > it's going to fail one way or another.[/color]

              Yes, that's one example. This doesn't mean that this implication always
              holds. What part of "doesn't imply" is the one you don't understand?
              [color=blue]
              > OK, the bad call of that function might never be reachable in actual
              > execution, but equally the syntax error in Tcl code might not be
              > reached. I'd rather find out about both kinds of mistake sooner
              > rather than later.[/color]

              I don't care for unreachable code in this specific context. A part of
              the program that passes a value of type "don't know" to a variable of
              type "don't know" might be unacceptable to a static type sytem, but
              might still not throw any exceptions at all at runtime. Or, in other
              scenarios, only exceptions that you can correct at runtime, which might
              be still useful, or even the preferred behavior.
              [color=blue]
              > (I do mean a type error and not a type 'error' - obviously if you have
              > some mechanism to catch exceptions caused by passing the wrong type,
              > you wouldn't want this to be checked at compile time.)[/color]

              Exactly.


              Pascal

              --
              Pascal Costanza University of Bonn
              mailto:costanza @web.de Institute of Computer Science III
              http://www.pascalcostanza.de Römerstr. 164, D-53117 Bonn (Germany)

              Comment

              • Joe Marshall

                Re: Python from Wise Guy's Viewpoint

                Matthias Blume <find@my.addres s.elsewhere> writes:
                [color=blue]
                > Ed Avis <ed@membled.com > writes:
                >[color=green]
                >> Pascal Costanza <costanza@web.d e> writes:
                >>[color=darkred]
                >> >>Should we then conclude that compile-time syntax checking is not
                >> >>worth having?
                >> >
                >> >No. Syntax errors make the program fail, regardless whether this is
                >> >checked at compile-time or at runtime.
                >> >
                >> >A type "error" detected at compile-time doesn't imply that the
                >> >program will fail.[/color]
                >>
                >> Actually it does, in a statically typed language.[/color]
                >
                > Nitpick: Neither syntactic nor statically checked type errors make
                > programs fail. Instead, their presence simply implies the absence of a
                > program. No program, no program failing...[/color]

                Nitpick: You are defining as a program that which passes a static type
                checker. What would you like to call those constructs that make sense
                to a human and would run correctly despite failing a static type
                check? These are the ones that are interesting to debate.

                Comment

                • Pascal Costanza

                  Re: Python from Wise Guy's Viewpoint

                  Matthias Blume wrote:[color=blue]
                  > Ed Avis <ed@membled.com > writes:
                  >
                  >[color=green]
                  >>Pascal Costanza <costanza@web.d e> writes:
                  >>
                  >>[color=darkred]
                  >>>>Should we then conclude that compile-time syntax checking is not
                  >>>>worth having?
                  >>>
                  >>>No. Syntax errors make the program fail, regardless whether this is
                  >>>checked at compile-time or at runtime.
                  >>>
                  >>>A type "error" detected at compile-time doesn't imply that the
                  >>>program will fail.[/color]
                  >>
                  >>Actually it does, in a statically typed language.[/color]
                  >
                  >
                  > Nitpick: Neither syntactic nor statically checked type errors make
                  > programs fail. Instead, their presence simply implies the absence of a
                  > program.[/color]

                  Yes, the absence of a program that might not fail if it wouldn't have
                  been rejected by the static type system.


                  Pascal

                  --
                  Pascal Costanza University of Bonn
                  mailto:costanza @web.de Institute of Computer Science III
                  http://www.pascalcostanza.de Römerstr. 164, D-53117 Bonn (Germany)

                  Comment

                  • Joe Marshall

                    Re: Python from Wise Guy's Viewpoint

                    [color=blue]
                    > Don Geddis <don@geddis.org > wrote:
                    >[color=green]
                    >> For example:
                    >> (defun foo (x)
                    >> (check-type x (integer 0 10))
                    >> (+ 1 x) )
                    >> (defun fib (n)
                    >> (check-type n (integer 0 *))
                    >> (if (< n 2)
                    >> 1
                    >> (+ (fib (- n 1)) (fib (- n 2))) ))
                    >> (print (foo (fib 5)))[/color]
                    >[color=green]
                    >> This program prints "9", and causes no run-time type errors. Will
                    >> it be successfully type-checked at compile time by a static system?
                    >> Almost certainly the answer is no.[/color][/color]

                    Dirk Thierbach <dthierbach@gmx .de> writes:[color=blue]
                    > It will be successfully type checked, because the static type system
                    > does not allow you to express assumptions about value ranges of types.[/color]

                    I was working on the assumption that the type language *would* allow
                    one to express arbitrary types. Certainly one can create a
                    sufficiently weak static type system that terminates under all
                    conditions and produces correct answers within the system. Lisp has
                    one: everything is a subtype of type t and all programs pass. The
                    inference is trivial.

                    But I surely wouldn't be impressed by a type checker that allowed this
                    to pass:

                    (defun byte-increment (x)
                    (check-type x (integer 0 (256)))
                    (+ x 1))

                    (defun fib (n)
                    (if (< n 2)
                    1
                    (+ (fib (- n 1)) (fib (- n 2)))))

                    (print (byte-increment (fib 13)))
                    [color=blue]
                    > On the other hand, if there is no static type mismatch, that doesn't
                    > mean that the program will not crash because of runtime errors
                    > (division by zero, or dynamically checked restrictions).[/color]

                    I think most people here were assuming that passing an integer greater
                    than 255 to a routine expecting a single 8-bit byte is a type error,
                    and something that could cause a crash.

                    Comment

                    • Pascal Costanza

                      Re: Static typing

                      John Atwood wrote:[color=blue]
                      > Pascal Costanza <costanza@web.d e> wrote:[/color]
                      [color=blue][color=green]
                      >>No, you definitely can do a lot of things with macros in Lisp that are
                      >>impossible to do in other languages. There are papers that show this
                      >>convincingl y. Try
                      >>ftp://publications.ai.mit.edu/ai-pub...df/AIM-453.pdf for a
                      >>start. Then continue, for example, with some articles on Paul Graham's
                      >>website, or download and read his book "On Lisp".[/color]
                      >
                      > That's a great paper; however, see Steele's later work:
                      > http://citeseer.nj.nec.com/steele94building.html[/color]

                      Yes, I have read that paper. If you want to work with monads, you
                      probably want a static type system.

                      (And I think he still likes Scheme and Lisp. ;)

                      Pascal

                      --
                      Pascal Costanza University of Bonn
                      mailto:costanza @web.de Institute of Computer Science III
                      http://www.pascalcostanza.de Römerstr. 164, D-53117 Bonn (Germany)

                      Comment

                      • Joe Marshall

                        Re: Python from Wise Guy's Viewpoint

                        Joachim Durchholz <joachim.durchh olz@web.de> writes:
                        [color=blue]
                        > prunesquallor@c omcast.net wrote:[color=green]
                        >> My point is that type systems can reject valid programs.[/color]
                        >
                        > And the point of the guys with FPL experience is that, given a good
                        > type system[*], there are few if any practial programs that would be
                        > wrongly rejected.[/color]

                        We're stating a pretty straightforward , objective, testable hypothesis:

                        ``There exists valid programs that cannot be statically checked by
                        such-and-such a system.''

                        and we get back

                        `yes, but...'
                        `in our experience'
                        `*I've* never seen it'
                        `if the type system is any good'
                        `few programs'
                        `no practical programs'
                        `no useful programs'
                        `isolated case'
                        `99% of the time'
                        `most commercial programs'
                        `most real-world programs'
                        `only contrived examples'
                        `nothings perfect'
                        `in almost every case'

                        Excuse us if we are skeptical.

                        Comment

                        • Fergus Henderson

                          Re: Test cases and static typing

                          Pascal Costanza <costanza@web.d e> writes:
                          [color=blue]
                          >What I want is:
                          >
                          >testxyz obj = (concretemethod obj == 42)
                          >
                          >Does the code compile as long as concretemethod doesn't exist?[/color]

                          No, because the likelihood of that being a typo (e.g. for `concrete_metho d')
                          is too high.

                          I recently added support to the Mercury compiler for an option
                          "--allow-stubs". For the equivalent code in Mercury, if this option
                          is enabled, then it will compile if there is a _declaration_ for
                          concretemethod, even if there is no _definition_. The compiler will
                          issue a warning and automatically generate a stub definition which just
                          throws an exception if it is ever called.

                          It would be fairly straight-forward to also add support for allowing
                          code like that to compile even if there was no declaration, but that
                          does not seems like a good idea to me -- it would make it easier for
                          typos to go unnoticed, with insufficient compensating benefit.

                          I'm sure it would also be easy for developers of other statically typed
                          languages to implement what you want, if they thought it was a good idea.

                          --
                          Fergus Henderson <fjh@cs.mu.oz.a u> | "I have always known that the pursuit
                          The University of Melbourne | of excellence is a lethal habit"
                          WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.

                          Comment

                          • Matthias Blume

                            Re: Python from Wise Guy's Viewpoint

                            Joe Marshall <jrm@ccs.neu.ed u> writes:
                            [color=blue][color=green]
                            > >
                            > > Nitpick: Neither syntactic nor statically checked type errors make
                            > > programs fail. Instead, their presence simply implies the absence of a
                            > > program. No program, no program failing...[/color]
                            >
                            > Nitpick: You are defining as a program that which passes a static type
                            > checker.[/color]

                            Yes, that's how it is usually done with statically typed languages.
                            [color=blue]
                            > What would you like to call those constructs that make sense
                            > to a human and would run correctly despite failing a static type
                            > check?[/color]

                            I don't know. What would you *like* to call them? (They might be
                            called "programs" -- just programs in another language.)
                            [color=blue]
                            > These are the ones that are interesting to debate.[/color]

                            Right, I am not disputing this. (I was simply nitpicking on
                            terminology.)

                            Matthias

                            Comment

                            • Neelakantan Krishnaswami

                              Re: Python from Wise Guy's Viewpoint

                              In article <bnjavv$v4c$2@f 1node01.rhrz.un i-bonn.de>, Pascal Costanza wrote:[color=blue]
                              > Matthias Blume wrote:[color=green]
                              >>
                              >> Nitpick: Neither syntactic nor statically checked type errors make
                              >> programs fail. Instead, their presence simply implies the absence of a
                              >> program.[/color]
                              >
                              > Yes, the absence of a program that might not fail if it wouldn't have
                              > been rejected by the static type system.[/color]

                              That sentence reflects a misunderstandin g of what something like ML's
                              type system *means*. You're trying to hammer ML into the Lisp mold,
                              which is leading you to incorrect conclusions.

                              A value in any programming language is some pattern of bits
                              interpreted under a type. In Scheme or Lisp, there is a single
                              universe (a single type) that that all values belong to, which is why
                              it's legal to pass any value to a function. But in ML, there are
                              multiple universes of values, one for each type.

                              This means that the same bit pattern can represent different values,
                              which is not true in a dynamically typed language. To make this
                              concrete, consider the following Ocaml code:

                              type foo = A | B

                              type baz = C | D

                              let f1 x =
                              match x with
                              | A -> C
                              | B -> D

                              let f2 x =
                              match x with
                              | C -> 0
                              | D -> 1

                              Some apparently-similar Scheme code would look like:

                              (define (f1 x)
                              (case x
                              ((A) 0)
                              ((B) 1)))

                              (define (f2 x)
                              (case x
                              ((C) 0)
                              ((D) 1)))

                              The difference between these two programs gets revealed when you look
                              at the assembly code that the Ocaml compiler produces for f1 and f2,
                              side by side[*]:

                              f1: f2:
                              ..L101: .L103:
                              cmpl $1, %eax cmpl $1, %eax
                              je .L100 je .L102
                              movl $3, %eax movl $3, %eax
                              ret ret
                              ..L100: .L102:
                              movl $1, %eax movl $1, %eax
                              ret ret

                              The code generated for each function is identical, modulo label names.
                              This means that the bit patterns for the data constructors A/C and B/D
                              are identical, and the the program only makes sense because A and C,
                              and B and D are interpreted at different types. (In fact, notice that
                              the bit-representation of the integer zero and and the constructors A
                              and C are the same, too.) In contrast, this would not be a valid
                              compilation of the Scheme program, because A, B, C, and D would all
                              have to have distinct bit patterns.

                              So eliminating the types from an ML program means you no longer have a
                              program, because you can no longer consistently interpret bit patterns
                              as ML values -- there *isn't* any universal domain that all ML values
                              really belong to, as you are supposing.
                              [*] I cleaned up some extraneous alignment stuff, to make what's going
                              on clearer. But all that was identical too.

                              --
                              Neel Krishnaswami
                              neelk@cs.cmu.ed u

                              Comment

                              • Matthias Blume

                                Re: Python from Wise Guy's Viewpoint

                                Pascal Costanza <costanza@web.d e> writes:
                                [color=blue]
                                > Matthias Blume wrote:[color=green]
                                > > Ed Avis <ed@membled.com > writes:
                                > >[color=darkred]
                                > >>Pascal Costanza <costanza@web.d e> writes:
                                > >>
                                > >>
                                > >>>>Should we then conclude that compile-time syntax checking is not
                                > >>>>worth having?
                                > >>>
                                > >>>No. Syntax errors make the program fail, regardless whether this is
                                > >>>checked at compile-time or at runtime.
                                > >>>
                                > >>>A type "error" detected at compile-time doesn't imply that the
                                > >>>program will fail.
                                > >>
                                > >>Actually it does, in a statically typed language.[/color]
                                > > Nitpick: Neither syntactic nor statically checked type errors make[/color]
                                >[color=green]
                                > > programs fail. Instead, their presence simply implies the absence of a
                                > > program.[/color]
                                >
                                > Yes, the absence of a program that might not fail if it wouldn't have
                                > been rejected by the static type system.[/color]

                                "would" "if" bah

                                You first have to define what the meaning of a phrase is going to be
                                if you let it slip past the type checker even though it is not
                                well-typed. As Andreas Rossberg pointed out, it is quite often the
                                case that the type is essential for understanding the semantics.
                                Simply ignoring types does not necessarily make sense under such
                                circumstances. So it all depends on how you re-interpret the language
                                after getting rid of static types.

                                Matthias

                                Comment

                                Working...