Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!csus.edu!ucdavis!ucbvax!CS.ARIZONA.EDU!gudeman From: gudeman@CS.ARIZONA.EDU ("David Gudeman") Newsgroups: comp.lang.icon Subject: Uses of dynamic typing Message-ID: <9011170801.AA19991@megaron.cs.arizona.edu> Date: 17 Nov 90 08:01:50 GMT References: <270675@Wayne-MTS> Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 40 One important use of dynamic typing is that the type itself gives some information. I write functions all the time where I _usually_ want a return value of a certain type, but on exceptional conditions I want something different. For example # factorial(i) return the factorial of i if i > = 0, # otherwise return &null. You can get much the same effect with exception handlers, but it has a different flavor. Another use is in program developement. The ability to assign different types to variables lets you try things out with fewer changes to a program. At least I think so. Two other features that help in this are polymorphism and automatic type conversions. Since Icon has all three, it is hard to say exactly which feature or set of features is most involved in this. Incidentally, there is no reason that run-time typing and static typing can't peacefully coexist in the same language. I can see two different ways of doing this: the first way is to say that all variables are untyped. This dynamically typed language also has type declarations that restrict the types that can be assigned to a given variable _at run time_. However, a given implementation _may_ give errors at compile time if a given path might lead to a type conflict. Furthermore, the implementation may optimize variables that always have a known type. The other way is to say that the language is statically typed, but that there are union types that carry type information around as a part of the union value. Also, all operators are overloaded so that they operate on the union types by checking the type at run time and doing the right operation. There is a specially named union type "any" that is a union of all other types. One might define that the default type of a variable is "any". Both of these paradigms allow the expressiveness of dynamic typing and the security and efficiency of static typing. In such a language, you can do developement with dynamic types and then "optimize" the program by declaring the types of most of the variables.