Article View: comp.lang.misc
Article #3421Re: Dynamic typing (part 3)
From: Lennart Augustsson
Date: Tue, 09 Apr 1991 11:02
Date: Tue, 09 Apr 1991 11:02
46 lines
2416 bytes
2416 bytes
In article <1593@optima.cs.arizona.edu> gudeman@cs.arizona.edu (David Gudeman) writes: >OK, try this. In mathematics you don't have to describe the types of >objects unless the type is important. In statically typed languages, >you have to declare the type whether it has any relevance or not (or >fix it at compile time whether it is really knowable or not). In >mathematics or dynamically typed languages you can describe the >concept of a set or a sequence, and operations over those data >structures, without refering to the "type" of elements. For example >in math you could say > > If f is a function and s is a sequence, then map(f,s) is the > sequence t such that for all i . t[i] = f(s[i]). > >In a Icon (a dynamically typed language) you could define > > procedure map(f,s) > local t,i > t := list(*s) > every i := 1 to *s do t[i] := f(s[i]) > return t > end > >Try to write this function in a statically typed language so that it >has all the generality of the math and Icon versions. (Actually, the >math version works for infinite sequences and the Icon one doesn't. >There are languages that fix that...) No, forget the challenge. Sorry, I can't forget it. I'll just have to make another plug for polymorhic type deduction. Here's a version of map in Haskell (ML would be very similar): map f [] = [] map f (x:xs) = f x : map f xs This also handles infinite lists (of course). Haskell is statically typed, and from the definition of map the compiler deduces (i.e. you don't have to write it, but you can if you like): map :: (a->b) -> [a] -> [b] Just because some statically typed languages requires you to declare the type whether it has any relevance or not does not mean that this is true for all of them. -- Lennart Augustsson [This signature is intentionally left blank.]
Technical Details
Message-ID:
<1991Apr9.110217.10963@mathrt0.math.chalmers.se>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!chalmers.se!mathrt0.math.chalmers.se!augustssReferences:
<1593@optima.cs.arizona.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!chalmers.se!mathrt0.math.chalmers.se!augustss From: augustss@cs.chalmers.se (Lennart Augustsson) Newsgroups: comp.lang.misc Subject: Re: Dynamic typing (part 3) Message-ID: <1991Apr9.110217.10963@mathrt0.math.chalmers.se> Date: 9 Apr 91 11:02:17 GMT References: <1593@optima.cs.arizona.edu> Sender: news@mathrt0.math.chalmers.se (Evald Nyhetsson) Organization: Dep of Computer Sciences, Chalmers, Gothenburg Lines: 46