Path: utzoo!news-server.csri.toronto.edu!bonnie.concordia.ca!ccu.umanitoba.ca!herald.usask.ca!alberta!aunro!aupair.cs.athabascau.ca!atha!decwrl!elroy.jpl.nasa.gov!usc!rpi!uupsi!sunic!chalmers.se!mathrt0.math.chalmers.se!augustss From: augustss@cs.chalmers.se (Lennart Augustsson) Newsgroups: comp.lang.misc Subject: Re: Dynamic typing -- To Have and Have Not (was R Message-ID: <1991Mar13.195039.22587@mathrt0.math.chalmers.se> Date: 13 Mar 91 19:50:39 GMT References: <614@optima.cs.arizona.edu> Sender: news@mathrt0.math.chalmers.se (Evald Nyhetsson) Organization: Dep of Computer Sciences, Chalmers, Gothenburg Lines: 44 In article <614@optima.cs.arizona.edu> gudeman@cs.arizona.edu (David Gudeman) writes: > ... And in any case, I claim that most people who >say they want static typing are ignorant of the alternative. I'll bet >that programmers who have programmed equally in both types of language >will overwhelmingly prefer dynamic typing (after correcting for the >stupid syntaxes that these languages seem prone to). I don't agree. I think that a lot of people who prefer dynamically typed languages are ignorant of the alternatives. Exactly as you I dislike to have to type all the extra type information that you have to do in Pascal, C etc. I also dislike not being able to make polymorphic functions (without cheating). But with languages like ML and Haskell with polymophic type systems and type inference you get static typing without the extra baggage. (Sure, there are still things you can do with dynamic typing that can't be done as easily with static typing; you can't get it all.) Taking your example and translating it to Haskell you'll get Icon: record tree(data,left,right) Haskell: data Tree a = Node a (Tree a) (Tree a) | Null Icon: # insert x into tree t and return the new tree procedure tree_insert(t,x) if t === &null return tree(x) if x <<< t.data then t.left := tree_insert(t.left,x) else t.right := tree_insert(t.right,x) return t end Haskell: (well, a side effect free version of the procedure above) tree_insert Null x = Node x Null Null tree_insert (Node y l r) x | x < y = Node (tree_insert l x) r tree_insert (Node y l r) x = Node l (tree_insert r x) The compiler infers the type (i.e. you don't have to write it!) tree_insert :: (Ord a) => Tree a -> a -> Tree a which means that tree_insert will work on any type of data that is a member of class Ord (i.e. has < defined). -- Lennart Augustsson [This signature is intentionally left blank.]