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.2 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 7BBE5BC69 for ; Thu, 18 Oct 2007 18:39:29 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAIcpF0fLENaMnmdsb2JhbACOTQIBAQcEBhEYgSc X-IronPort-AV: E=Sophos;i="4.21,296,1188770400"; d="scan'208";a="4742924" Received: from ipmail01.adl2.internode.on.net ([203.16.214.140]) by mail3-smtp-sop.national.inria.fr with ESMTP; 18 Oct 2007 18:39:28 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAOknF0d5LCRsWmdsb2JhbAAMjjcBIIFO X-IronPort-AV: E=Sophos;i="4.21,296,1188743400"; d="scan'208";a="213568150" Received: from ppp121-44-36-108.lns10.syd7.internode.on.net (HELO [192.168.1.201]) ([121.44.36.108]) by ipmail01.adl2.internode.on.net with ESMTP; 19 Oct 2007 02:09:25 +0930 Subject: Re: [Caml-list] Smells like duck-typing From: skaller To: Arnaud Spiwack Cc: caml-list@yquem.inria.fr In-Reply-To: <47177585.6030208@lix.polytechnique.fr> References: <377673.31302.qm@web54602.mail.re2.yahoo.com> <47176B4A.5000807@janestcapital.com> <47176DB6.7090700@lix.polytechnique.fr> <471771A7.3010402@janestcapital.com> <47177585.6030208@lix.polytechnique.fr> Content-Type: text/plain Date: Fri, 19 Oct 2007 02:39:24 +1000 Message-Id: <1192725564.5999.51.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; 0200,:01 supertype:01 subtype:01 subtype:01 subtyping:01 subtypes:01 mutable:01 symmetric:01 symmetric:01 subtypes:01 sourceforge:01 wrote:01 arnaud:01 caml-list:01 constraint:01 On Thu, 2007-10-18 at 17:02 +0200, Arnaud Spiwack wrote: > > > > Saying that A is a supertype of B is the equivelent of saying B is a > > subtype of A. Same relation, different direction. In OO lingo, how > > they say "B is a subtype of A" is that "B inherits from (is a subclass > > of) A". > That's not true. That's how you say it in *some* Object Oriented > languages. Inheritance is a tool which allows you to derive another > object from another one. You like it to be a subtype though, it usually > is rather difficult to build a sound inheritance system where it can > break subtyping anyway That isn't so, almost ALL derived types fail to be subtypes. In particular, this is always the case when there is a mutator, because derived values are covariant but mutators are contravariant, on the other hand Object Orientation intrinsically deals with mutable state .. QED. This combination destroys the OO paradigm instantly, [quite apart from the usual linearity constraint which make it impossible for OO to handle any kind of relationship] To understand this simply consider a matrix (base type) and a symmetric matrix (derived type). Every symmetric matrix 'is-a' matrix. Fine. It works as a value. But add a mutator, 'setxy(x,y)' with property that only element x,y is modified and you're screwed: derived class mutators work on the base, but not the other way around. The soundness theory is simple: methods have to be covariant, but mutators have to be contravariant, and since mutators are also method they have to be *invariant*, and invariance effectively means an OO class cannot have subtypes. The effect is, given some class type T, the ONLY thing you are allowed to do with inheritance is implement it, you cannot actually derive a new type. [Now someone who understands the theory better than me can re-explain this ..:] -- John Skaller Felix, successor to C++: http://felix.sf.net