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 306C6BBAF for ; Tue, 22 Dec 2009 14:36:39 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtwCAMJaMEvZSMDji2dsb2JhbACBSploAQEBCgsKBxEFuXGEMwQ X-IronPort-AV: E=Sophos;i="4.47,436,1257116400"; d="scan'208";a="42587047" Received: from fmmailgate02.web.de ([217.72.192.227]) by mail1-smtp-roc.national.inria.fr with ESMTP; 22 Dec 2009 14:36:32 +0100 Received: from smtp05.web.de (fmsmtp05.dlan.cinetic.de [172.20.4.166]) by fmmailgate02.web.de (Postfix) with ESMTP id 3B6AA149E7F60; Tue, 22 Dec 2009 14:35:38 +0100 (CET) Received: from [95.208.117.111] (helo=frosties.localdomain) by smtp05.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #314) id 1NN4tL-0001zU-00; Tue, 22 Dec 2009 14:35:11 +0100 Received: from mrvn by frosties.localdomain with local (Exim 4.69) (envelope-from ) id 1NN4tK-0008G6-Lm; Tue, 22 Dec 2009 14:35:10 +0100 From: Goswin von Brederlow To: boris@yakobowski.org Cc: Goswin von Brederlow , Damien Guichard , caml-list caml-list Subject: Re: [Caml-list] obj.magic for polymorphic record fields References: <531142069376641352@orange.fr> <87zl5cmof9.fsf@frosties.localdomain> <76c7f53f0912210600y91c9b76ib07d130cf7cf251f@mail.gmail.com> Date: Tue, 22 Dec 2009 14:35:10 +0100 In-Reply-To: <76c7f53f0912210600y91c9b76ib07d130cf7cf251f@mail.gmail.com> (Boris Yakobowski's message of "Mon, 21 Dec 2009 15:00:19 +0100") Message-ID: <87eimnrv1t.fsf@frosties.localdomain> User-Agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.4.22 (linux) 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: V01U2FsdGVkX19iSUW9XtLlyZ0hU890MZYYw/gjNsaiE20tXYCH y5TEfZL3TbOFDKOwPUH7TGfVUaRJ2rIcsSL1Bx1uohMlAm4UOl RGtYWy9uY= X-Spam: no; 0.00; yakobowski:01 yakobowski:01 inference:01 ocaml:01 compiler:01 compiler:01 baz:01 baz:01 inference:01 2009:98 crystal:98 mfg:98 polymorphic:01 wrote:01 caml-list:01 Boris Yakobowski writes: > On Mon, Dec 21, 2009 at 2:44 PM, Goswin von Brederlow wrote: >>> However it issues a warning so i acknowledge it's less elegant. >> >> Which I don't quite understand. > > The warning is based on the results of the type inference algorithm. > You're not supposed to find values of type 'a. 'a "in the wild", yet > (Obj.magic a) has this type. Thus the Ocaml compiler deduces that > you're doing something wrong: your function never returns, it does not > use its arguments, etc. Here, using Obj.magic breaks the crystal ball > of the compiler, and the warning is incorrect. > > There is an easy way to silence the warning though: > > let baz = {bar = fun x -> (Obj.magic a : _ -> _) x} > > (but not let baz = {bar = fun x -> (Obj.magic a : 'a -> 'a) x} for > ugly reasons...) > > You are however quite correct. Using Obj.magic in this particular case > seems quite wrong. > > -- > Boris But the type inference should deduce that in (Obj.magic fn) x the 'a is actually 'b -> 'c as I am applying an argument to it. Seems to me there is something special for Obj.magic so it doesn't automatically cast values to functions. MfG Goswin