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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 0D92CBC57 for ; Mon, 1 Mar 2010 21:13:23 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhEBAF6ui0tRZ90xkWdsb2JhbACbBxUBAQEBCQsKBxMDH7w6gk+CLAQ X-IronPort-AV: E=Sophos;i="4.49,561,1262559600"; d="scan'208";a="53829232" Received: from mtaout03-winn.ispmail.ntl.com ([81.103.221.49]) by mail1-smtp-roc.national.inria.fr with ESMTP; 01 Mar 2010 21:13:22 +0100 Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout03-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20100301201322.OJLU10950.mtaout03-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com>; Mon, 1 Mar 2010 20:13:22 +0000 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout01-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20100301201322.QOVU13254.aamtaout01-winn.ispmail.ntl.com@romulus.metastack.com>; Mon, 1 Mar 2010 20:13:22 +0000 Received: from Tenor ([212.183.140.54]) (authenticated bits=0) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id o21KD0Bl021431 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Mon, 1 Mar 2010 20:13:09 GMT From: "David Allsopp" To: "'Goswin von Brederlow'" , "'OCaml List'" References: <4B887AED.3090005@citycable.ch> <4B88F32C.3050701@citycable.ch> <87k4tyoq3m.fsf@frosties.localdomain> <4B891A0C.604@citycable.ch> <76EDF2F2-8B02-4C97-B083-EC74630D8ECA@mpi-sws.org> <4B896026.2070805@citycable.ch> <4B89780E.5080305@citycable.ch> <4B898179.1000600@citycable.ch> <4B8B9D15.7070300@glondu.net> <4B8BA350.8090404@citycable.ch> <000d01cab93d$b095c770$11c15650$@romulus.metastack.com> <87ocj8jhmj.fsf@frosties.localdomain> In-Reply-To: <87ocj8jhmj.fsf@frosties.localdomain> Subject: RE: [Caml-list] Recursive subtyping issue Date: Mon, 1 Mar 2010 20:12:57 -0000 Message-ID: <004101cab97b$a0a19360$e1e4ba20$@romulus.metastack.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQG++dev6usjy+MhCCiCMQMXQZ/itALZ1N3bAhDBEaACMQ+SQQJi1d9iAtZavDECFUz3DwKgUGxPA1Sa9KMBLUbUWwG7IK8HAbcyleECIYhaEgI2HFNL Content-Language: en-gb Organization: MetaStack Solutions Ltd. X-Scanned-By: MIMEDefang 2.65 on 81.102.132.77 X-Cloudmark-Analysis: v=1.1 cv=W3tOLUehizD4qj6VhtReFuw5MKb8d+XqjIxlDsIazEA= c=1 sm=0 a=wNs1GRMElQMA:10 a=SGJpDYsEAAAA:8 a=ZOzjf2MOAAAA:8 a=GKxPZAyOYBAu2JJtFbIA:9 a=u9TwCWmly_HR8oXhVaQA:7 a=Xmxr5ESYWSzgNhqQ-qRkptkefWwA:4 a=dTth3pfvbawA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 X-Spam: no; 0.00; recursive:01 subtyping:01 foo:01 foo:01 mli:01 ocamlopt:01 asmcomp:01 cmmgen:01 val:01 ocamlopt:01 eliminates:98 afc:98 wrote:01 signatures:01 caml-list:01 Goswin von Brederlow wrote: > "David Allsopp" writes: > > > external foo_of_bar : bar -> foo = "%identity" > > > > in *both* the .ml and .mli file for the module in question. I'm > virtually certain that ocamlopt eliminates calls to the %identity > primitive. > > Where is that documented? The use of external and its benefit in exported signatures is documented in Chapter 18 of the manual. I believe I became aware of the %identity special handling as a side-effect of the discussion in http://caml.inria.fr/pub/ml-archives/caml-list/2007/04/200afc54d9796dbb7a8d7 5bef70f2496.en.html. If you look in asmcomp/cmmgen.ml you'll see what I think is the elimination of Pidentity calls in the code generator. > I would have written > > let foo_of_bar (x : bar) = (x :> foo) We're solving two different problems, I think (as you're assuming that bar can be constrained to type foo) - I'm assuming that all type constraining is done in the signature of the interface so, without %identity I would simply have put [let foo_of_bar x = x] of type 'a -> 'a in my module... and then constrained it as [val foo_of_bar : bar -> foo] in the signature. It is possible that ocamlopt can recognise (obvious) identity functions as well, but that's just speculation on my part as I haven't looked. David