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.3 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 313D6BC69 for ; Thu, 18 Oct 2007 19:47:16 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAA05F0fLENaMnmdsb2JhbACOTQIBAQcEBhEY X-IronPort-AV: E=Sophos;i="4.21,296,1188770400"; d="scan'208";a="3227407" Received: from ipmail01.adl2.internode.on.net ([203.16.214.140]) by mail1-smtp-roc.national.inria.fr with ESMTP; 18 Oct 2007 19:47:15 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAIA5F0d5LCRsWmdsb2JhbAAMjjcBIA X-IronPort-AV: E=Sophos;i="4.21,296,1188743400"; d="scan'208";a="213600511" 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 03:17:12 +0930 Subject: Re: [Caml-list] Smells like duck-typing From: skaller To: Arnaud Spiwack Cc: caml-list@yquem.inria.fr In-Reply-To: <47178E8C.6020304@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> <1192725564.5999.51.camel@rosella.wigram> <47178E8C.6020304@lix.polytechnique.fr> Content-Type: text/plain Date: Fri, 19 Oct 2007 03:47:11 +1000 Message-Id: <1192729631.5999.103.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; 0200,:01 subtypes:01 subtypes:01 subtype:01 theorems:01 invariants:01 mutable:01 subtype:01 mutable:01 complicates:01 cart:98 sourceforge:01 wrote:01 wrote:01 arnaud:01 On Thu, 2007-10-18 at 18:49 +0200, Arnaud Spiwack wrote: > skaller wrote : > > 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. > > > You got that part wrong. I means that subtypes have the same types for > the same methods (not subtypes, exactly the same types), but it can be > extended with extra methods (you can be slighlty looser using > specialisation of the self-type). That's how things work. I don't think so but I may have misunderstood: the problem is, you're thinking of values again. With a value subtype, the extra invariant adds extra structure which can admit new interesting theorems, so you can add new methods to calculate them. But that never happens with mutators because you cannot HAVE any additional invariants. The derived type has to have exactly the same set of values as the base, in which case you cannot have any new interesting methods -- any method you have can always be defined in terms of the characteristic methods already in the base (assuming the whole public state is accessible of course). Note I am simplifying since real objects are a mix of mutable and immutable state, in that case of course you can subtype the immutable state and leave the mutable state invariant. But that's just factorisation which complicates the argument. >>From that view point there is actually only ONE possible mutator: assignment (since, you can always construct the new state in a new object and assign it, there is no need for any partial mutators). For example for a mutable complex number you do not need 'set_real(), set_imaginary()' mutators, you only need a constructor Cart(r,i) plus assignment. -- John Skaller Felix, successor to C++: http://felix.sf.net