From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 9AFDBBC57 for ; Sun, 28 Mar 2010 19:08:30 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtMAAEcqr0uLEwExkWdsb2JhbACbKBUBAQEBCQsKBxEFHa8kAY06BYUB X-IronPort-AV: E=Sophos;i="4.51,323,1267398000"; d="scan'208";a="59832659" Received: from hera.mpi-sb.mpg.de ([139.19.1.49]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 28 Mar 2010 19:07:54 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mpi-sb.mpg.de; s=mail200803; h=From:To:In-Reply-To:Subject: References:Message-Id:Content-Type:Content-Transfer-Encoding: Mime-Version:Date:Cc; bh=k82ZX4nHRVBknodNBKQ/vBiec/PS8nzHLOklwyA 49sg=; b=FUpqBOcgzLo8tO1D8/saj7fUItdIQXx0wGfLWULENpSWDwoEWdzxeUG kYQ53OsVlokD6E4c6pZVcVpANaG+XhPvbKruFbc2n4eilDZTVAMa+JMAMqcqv14S ktS0f3/99rDi9H29fY6DhF3hG6+xGorUaFZAoW4zs932PiJ4J1L8= Received: from infao0710.mpi-sb.mpg.de ([139.19.1.27]:48109 helo=zak.mpi-sb.mpg.de) by hera.mpi-sb.mpg.de (envelope-from ) with esmtp (Exim 4.69) id 1Nvvxn-000887-B9; Sun, 28 Mar 2010 19:07:53 +0200 Received: from p5de95f53.dip.t-dialin.net ([93.233.95.83]:56517 helo=[192.168.2.112]) by zak.mpi-sb.mpg.de with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1Nvvxm-00084W-9X; Sun, 28 Mar 2010 19:07:50 +0200 From: Andreas Rossberg To: Dario Teixeira In-Reply-To: <61102.44294.qm@web111503.mail.gq1.yahoo.com> Subject: Re: [Caml-list] Structural subtyping problem References: <61102.44294.qm@web111503.mail.gq1.yahoo.com> Message-Id: Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v936) Date: Sun, 28 Mar 2010 19:07:45 +0200 Cc: caml-list@yquem.inria.fr X-Mailer: Apple Mail (2.936) X-Spam: no; 0.00; rossberg:01 rossberg:01 subtyping:01 subtyping:01 ocaml's:01 intuitively:01 compiler:01 annotations:01 coercions:01 coercions:01 recursion:01 recursion:01 ocaml:01 28,:98 polymorphic:01 On Mar 28, 2010, at 18.38 h, Dario Teixeira wrote: > Hi, > > I'm using the structural subtyping aspects of Ocaml's object system > to emulate width > subtyping. I've come across a problem which does not type-check, > though intuitively > it seems correct. I reckon that the compiler may need some help in > the form of type > annotations and/or coercions, though their exact shape elludes me. > > A simple nonsensical example that illustrates the problem is listed > below; the > type-checking error occurs in function "step1", where the optional > parameter "story" > is used as an object of type "< title:string; .. >". In function > "step3", this > parameter "story" is actually instantiated with objects of type "< > title:string >" > and "< title:string; count:int >". > > Anyway, am I correct in assuming this should be feasible? And if > so, what coercions > are required to make this compile? You problem is just that you try to use step1 polymorphically within a recursion. Polymorphic recursion is not (yet) allowed in OCaml. You can side-step it by coercing the argument to a suitable monomorphic type in all uses of step1. In your example, that solution just consists of changing step3 as follows: > and step3 ~story = match story#count with > | 0 -> > let story = (story :> ) > in step1 ~story () > | 1 -> > ... /Andreas