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 92D54BC57 for ; Tue, 2 Mar 2010 11:22:06 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhoDAJd1jEvZSMDjimdsb2JhbACafhUBAQEKCQwHEQUfviCCT4IsBA X-IronPort-AV: E=Sophos;i="4.49,565,1262559600"; d="scan'208";a="53860757" Received: from fmmailgate02.web.de ([217.72.192.227]) by mail1-smtp-roc.national.inria.fr with ESMTP; 02 Mar 2010 11:22:06 +0100 Received: from smtp08.web.de (fmsmtp08.dlan.cinetic.de [172.20.5.216]) by fmmailgate02.web.de (Postfix) with ESMTP id B44A31510E225 for ; Tue, 2 Mar 2010 11:22:05 +0100 (CET) Received: from [85.216.85.71] (helo=frosties.localdomain) by smtp08.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #314) id 1NmPEr-00037m-00 for caml-list@inria.fr; Tue, 02 Mar 2010 11:22:05 +0100 Received: from mrvn by frosties.localdomain with local (Exim 4.71) (envelope-from ) id 1NmPEq-0003dp-Uh for caml-list@inria.fr; Tue, 02 Mar 2010 11:22:05 +0100 From: Goswin von Brederlow To: "'OCaml List'" Subject: Re: [Caml-list] Recursive subtyping issue 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> <004101cab97b$a0a19360$e1e4ba20$@romulus.metastack.com> Date: Tue, 02 Mar 2010 11:22:04 +0100 In-Reply-To: <004101cab97b$a0a19360$e1e4ba20$@romulus.metastack.com> (David Allsopp's message of "Mon, 1 Mar 2010 20:12:57 -0000") Message-ID: <87r5o3hvlf.fsf@frosties.localdomain> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX1/ULlqgQy/z0GlN3n2WI/LWvTuE6h2W91wn1aEA Wr7kSWMzaG0iYndcdyuepxcajftg1Z2u5VgOgAejhqrrzuXcNz pwdkCKv2E= 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 eliminates:98 mfg:98 wrote:01 "David Allsopp" writes: > 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. Meaning it is not documented. :( >> 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. It probably won't detect it as identity function but it probably always inlines it and thereby eliminates it. I hope. MfG Goswin