Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!deccrl!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!edcastle!cs.ed.ac.uk!db From: db@cs.ed.ac.uk (Dave Berry) Newsgroups: comp.lang.misc Subject: Re: Dynamic typing (part 3) Message-ID: <8078@skye.cs.ed.ac.uk> Date: 21 Mar 91 15:29:07 GMT References: <602@optima.cs.arizona.edu> <2400034@otter.hpl.hp.com> Sender: nnews@cs.ed.ac.uk Reply-To: db@lfcs.ed.ac.uk (Dave Berry) Organization: Laboratory for the Foundations of Computer Science, Edinburgh U Lines: 58 In article <2400034@otter.hpl.hp.com> sfk@otter.hpl.hp.com (Steve Knight) writes: >As you can see, modern programming languages that support polymorphic >type-checking and type-inference give you all the security and performance >enhancements of a strongly typed language and all the flexibility and >convenience of a dynamically typed language. No-one claimed that ML gives you all the flexibility of dynamic typing. Someone pointed out that you don't need to declare types in a strongly typed language, which ML shows is true. ML also shows that you can have incremental compilation and interactive environments with strongly typed languages. It's a pity that so many people seem unable to separate one feature of a language (or set of languages) from other features of those langauges. Some of Steve's examples show the sort of thing that can't be done in a (purely) strongly typed language. For example, >- val foo = [false, 0]; >Error: operator and operand don't agree (tycon mismatch) There's no way that you can know the type of the head of a list containing both integer and booleans without either: 1. Dynamic typing. 2. Tagging each element. A subtype hierarchy (of some sort or other) would let you specify a general type for the elements in the list, and dynamic binding would let you call type-specific functions on each element. This is the sort of thing done in Eiffel and C++. It still doesn't give you the actual type of each element. There are schemes for adding dynamic types to strongly typed languages that would let you do things like this. They preserve type-safety by requiring explict coercions from the type "dynamic" to the desired type, which only succeeds if the object really is of the desired type. (It's likely that one of these will appear in ML at some point.) So it seems that designers of strongly-typed languages are looking at facilities to use dynamic types when they are needed, and designers of dynamically-typed languages are looking at facilities to have type-checking when needed. Perhaps we should stop arguing and start co-operating. >It is not possible to write a polymorphic hash-function. I don't see how it's possible to write a polymorphic hash-function in any language unless you know all the possible types or type-representations that the language will ever have, at the time when you write the function. Is this necessarily the case with dynamically-typed lanaguges? How could you write a polymorphic hash-function in SmallTalk? Redefining the function in each sub-class is not acceptable - you can make the equivalent definition in ML (you don't have dynamic binding, but that wasn't Steve's point). Steve's other comments about ML aren't relevant top the subject, so I'll comment on them in a different message. -- Dave Berry, LFCS, Edinburgh Uni. db%lfcs.ed.ac.uk@nsfnet-relay.ac.uk George Bush: America's Chamberlain.