From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 81EF1BC0C for ; Sat, 23 Dec 2006 05:11:50 +0100 (CET) Received: from host15.ipowerweb.com (host15.ipowerweb.com [66.235.219.115]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id kBN4BkSe024694 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Sat, 23 Dec 2006 05:11:50 +0100 Received: from c-24-9-123-251.hsd1.co.comcast.net ([24.9.123.251] helo=apotheon.com) by host15.ipowerweb.com with esmtp (Exim 4.52) id 1GxyEW-0003qy-Vv; Fri, 22 Dec 2006 20:11:41 -0800 Received: by apotheon.com (Postfix, from userid 1000) id 290B433433; Fri, 22 Dec 2006 21:11:22 -0700 (MST) Date: Fri, 22 Dec 2006 21:11:22 -0700 From: Chad Perrin To: skaller Cc: Chad Perrin , caml-list@yquem.inria.fr Subject: Re: strong/weak typing terminology (was Re: [Caml-list] Scripting in ocaml) Message-ID: <20061223041121.GA31700@apotheon.com> References: <20061221221650.GL9440@apotheon.com> <3EC73FC3-41A6-4FB1-9549-29286A6568CC@epfl.ch> <1166811403.6555.46.camel@rosella.wigram> <4E1EAAC5-DC08-4A55-9AEB-0D5D3BE1C0EA@epfl.ch> <1166816522.7448.45.camel@rosella.wigram> <458C39FD.7090409@davidb.org> <20061222201725.GC23003@apotheon.com> <1166845703.7448.172.camel@rosella.wigram> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1166845703.7448.172.camel@rosella.wigram> User-Agent: Mutt/1.5.13 (2006-08-11) X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - host15.ipowerweb.com X-AntiAbuse: Original Domain - yquem.inria.fr X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - apotheon.com X-Source: X-Source-Args: X-Source-Dir: X-Miltered: at discorde with ID 458CAC82.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 type-safe:01 statically:01 abstraction:01 statically:01 runtime:01 casts:01 pointers:01 type-related:01 ocaml:01 mismatch:01 buffer:01 type-safe:01 23,:98 wrote:01 On Sat, Dec 23, 2006 at 02:48:23PM +1100, skaller wrote: > On Fri, 2006-12-22 at 13:17 -0700, Chad Perrin wrote: > > > This all seems rather simple to me: > > > > It's type-safe if you cannot get type errors without subverting the type > > system. > > You are missing something. There's no such thing as a 'type error' > at run time in a statically typed language. At run time object values > are just bit strings, they don't HAVE any types -- and even that > is an abstraction (really you just have registers and machine > code .. not even really bit strings). That's not quite true. A "type error" is what happens when an operation is performed on a value of a type different from the operation's type. For instance, integer addition on a float or string, or concatenation on an integer or float, is a type error in most languages. Statically typed languages are commonly thought to avoid such type errors at runtime almost tautologically, but play with casts and pointers in some dangerous ways in C/C++ and you may quickly learn that is not the case. > > Python has a static type system. Did you know? Everything has > type 'object'. That's a pretty weird interpretation of the Python type system -- and it's categorically false, because there are many things in Python that are not objects. You might be able to make such a claim for Ruby, even though I would consider even that to be a dubious claim due to the other type-related behavior of the language. In fact, objects have types. That's sorta the point of objects, from a certain perspective: defining types to extend your type system in a manner that makes it possible to achieve certain benefits in coding such as reusability and modularity. > > So in fact Python is quite type safe, and statically so. > Big deal. The type system isn't expressive enough for that > to mean anything! > > Similarly, Ocaml is NOT type safe because array bounds can > be violated at run time. This is because the type system > is not expressive enough to capture the array bound as > part of the type. I don't know OCaml quite well enough to say this with authority, but at a guess I'd say that's not a type error. It's an error, but not a type error, because it does not involve applying an operation to a value of a given type (or similarly mismatch types). It's more akin to a buffer overrun than a type error. Also, this directly contradicts your own earlier definition of "type safety", because OCaml is pretty clearly a statically typed language. > > So saying a language is type-safe is meaningless unless > you also say how expressive the type system is: either > way the program isn't safe, and the choice of typing is > often dictated by what can be statically checked, rather > than what NEEDS to be checked. So 'type safe' is a fairly > vague concept in this sense. > > It really comes down to "I think Ocaml is a better programming > language for my purpose than C++". So much for language theory. I guess it's all balderdash, then. By the way, I wrote a longish email (I didn't think it was *THAT* long, but apparently it was) earlier today that never made it through to the list. I can only guess that it must be in moderation because of its length. It gets into some depth on the subject of defining type system characteristics, and might be worth a read if it ever appears. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] "A script is what you give the actors. A program is what you give the audience." - Larry Wall