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 D4E96BBAF for ; Mon, 21 Dec 2009 15:00:40 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ap4CAGoOL0vRVdvSkGdsb2JhbACbEz8BAQEBCQkMBxMDrFGEGYgjAQIDBYQpBIsw X-IronPort-AV: E=Sophos;i="4.47,431,1257116400"; d="scan'208";a="52597952" Received: from mail-ew0-f210.google.com ([209.85.219.210]) by mail4-smtp-sop.national.inria.fr with ESMTP; 21 Dec 2009 15:00:40 +0100 Received: by ewy2 with SMTP id 2so6027909ewy.7 for ; Mon, 21 Dec 2009 06:00:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:reply-to:received :in-reply-to:references:from:date:x-google-sender-auth:message-id :subject:to:cc:content-type; bh=xA068RPbe9oSLUEsvGtc+H3jZeUupYK5JlAsm6hp70o=; b=qtpx8OY2GBmUss/ldzpi6wLgj7CjMsKZIsQOwN1qkARzAnSl8vQwfSqd6RII2WXB68 z6HPh5dum6jGaflgy9J4hDm0U12+kl0Ku3Rwlnet0rfZmimm1sDf22tAJCvmKCsdhFIH 58Bn7yKTxgXpJHBVWBXay8xVEM7RL29UOJCRM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:reply-to:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; b=hBZ6WMd7hLYPN9Nz019tiGUwNAvh6pjtNF7W349UfKYNuBaLbAkAeQdgQ2Lq99vvq3 58eQeDHx8MpDNwDjRNuwReQXdV7nT6EyPlKRIySTzCmI0PCnnO2P8iwEWgdswf09OKQR EwX1KxkXuAPPWG/KHFWpSBHyNth5PgcbYmrcY= MIME-Version: 1.0 Sender: cppcrazy@gmail.com Reply-To: boris@yakobowski.org Received: by 10.213.100.11 with SMTP id w11mr5676915ebn.34.1261404039159; Mon, 21 Dec 2009 06:00:39 -0800 (PST) In-Reply-To: <87zl5cmof9.fsf@frosties.localdomain> References: <531142069376641352@orange.fr> <87zl5cmof9.fsf@frosties.localdomain> From: Boris Yakobowski Date: Mon, 21 Dec 2009 15:00:19 +0100 X-Google-Sender-Auth: fa6069771ddb56ae Message-ID: <76c7f53f0912210600y91c9b76ib07d130cf7cf251f@mail.gmail.com> Subject: Re: [Caml-list] obj.magic for polymorphic record fields To: Goswin von Brederlow Cc: Damien Guichard , caml-list caml-list Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; yakobowski:01 yakobowski:01 inference:01 ocaml:01 compiler:01 compiler:01 baz:01 baz:01 2009:98 crystal:98 polymorphic:01 wrote:01 caml-list:01 algorithm:01 breaks:02 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