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 B930CBC57 for ; Mon, 1 Mar 2010 14:32:47 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AswCAOVQi0tV2gB5h2dsb2JhbACDBJgfAQEBCgsIBxUiiBuhXI80gTSBG4FCagSDM4Y/ X-IronPort-AV: E=Sophos;i="4.49,560,1262559600"; d="scan'208";a="57967657" Received: from emailfrontal2.citycable.ch ([85.218.0.121]) by mail4-smtp-sop.national.inria.fr with SMTP; 01 Mar 2010 14:32:47 +0100 Received: from [192.168.0.12] (unknown [85.218.92.99]) (Authenticated sender: guillaume.yziquel@citycable.ch) by emailfrontal2.citycable.ch (Postfix) with ESMTPA id 72DF6834584; Mon, 1 Mar 2010 14:32:31 +0100 (CET) Message-ID: <4B8BC220.8030904@citycable.ch> Date: Mon, 01 Mar 2010 14:33:20 +0100 From: Guillaume Yziquel Reply-To: guillaume.yziquel@citycable.ch User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090707) MIME-Version: 1.0 To: David Allsopp Cc: =?UTF-8?B?J1N0w6lwaGFuZSBHbG9uZHUn?= , '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> In-Reply-To: <000d01cab93d$b095c770$11c15650$@romulus.metastack.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; guillaume:01 guillaume:01 recursive:01 subtyping:01 subtyping:01 foo:01 foo:01 mli:01 ocamlopt:01 usr:01 lib:01 ocaml:01 mli:01 runtime:01 ocamldoc:01 David Allsopp a =C3=A9crit : > Guillaume Yziquel wrote: >> St=C3=A9phane Glondu a =C3=A9crit : >> >>> Why don't you just declare 'a t to be synonym for obj in the >>> implementation of your module, declare them as abstract in its >>> interface, and export the specially typed identities f and g? >> >> Because subtyping seems more efficient than applying a noop function. >=20 > I wholeheartedly agree that doing this in the type system is much clean= er than using noop/coercion functions but I don't think that there's any = difference in terms of efficiency. If the noop/coercion functions are cor= rectly coded then they will be of the form: >=20 > external foo_of_bar : bar -> foo =3D "%identity" >=20 > in *both* the .ml and .mli file for the module in question. I'm virtual= ly certain that ocamlopt eliminates calls to the %identity primitive. yziquel@seldon:~$ grep magic /usr/lib/ocaml/obj.mli external magic : 'a -> 'b =3D "%identity" So far so good. >> Moreover, having conversion functions is not really handy, from a >> syntactic point of view: It's quite convenient to write something like >> >> let f : string -> obj :> string -> float t =3D blah blah blah... >> >> than doing the explicit, runtime, casting in the definition of f. >=20 > Agreed - this is where your approach is really neat! I'm not so sure how far we can push the idea. You can, in one ':>', do=20 subtyping at every type in the type 'a -> 'b -> 'c. This is quite handy.=20 But I'll have to check in which way this can be integrated in the=20 calling conventions of, say, Python. >> I then tried to go the whole way, and get rid of conversion functions >> altogether. >=20 > Being pedantic, what you mean is getting rid of *coercion* functions; *= conversion* functions could never eliminated OK. > This is tremendously clean - as long as the types are clearly documente= d! The problem is that ocamldoc doesn't let you "document" coercions (by = which I mean that having a conversion function provides means for the doc= umentation of that particular usage). Thank you. The ocamldoc problem isn't really a problem, I believe. You=20 just have to write it cleanly in bold letters. What is more a problem is the fact that inferred .mli files tend to=20 leave out the contravariance on tau: http://caml.inria.fr/mantis/view.php?id=3D4988 And hence drops part of the subtyping facility. --=20 Guillaume Yziquel http://yziquel.homelinux.org/