From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 67C017EE51 for ; Thu, 9 May 2013 02:57:47 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of markus.mottl@gmail.com) identity=pra; client-ip=209.85.212.172; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="markus.mottl@gmail.com"; x-sender="markus.mottl@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of markus.mottl@gmail.com designates 209.85.212.172 as permitted sender) identity=mailfrom; client-ip=209.85.212.172; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="markus.mottl@gmail.com"; x-sender="markus.mottl@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f172.google.com) identity=helo; client-ip=209.85.212.172; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="markus.mottl@gmail.com"; x-sender="postmaster@mail-wi0-f172.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AikCAAP0ilHRVdSsk2dsb2JhbABSgz6DPLtvcggWDgEBAQEHCwsJFAQkgh8BAQQBIx0BFAcdAQMBCwYFCw0CAiYCAiEBAREBBQEcBhMbh14BAwkGpDuLbk+CfoRKChknDViHRwEFDIEaiyyCIzMHgkKBEwOTXYFrgWSME4M9FimEUSA X-IPAS-Result: AikCAAP0ilHRVdSsk2dsb2JhbABSgz6DPLtvcggWDgEBAQEHCwsJFAQkgh8BAQQBIx0BFAcdAQMBCwYFCw0CAiYCAiEBAREBBQEcBhMbh14BAwkGpDuLbk+CfoRKChknDViHRwEFDIEaiyyCIzMHgkKBEwOTXYFrgWSME4M9FimEUSA X-IronPort-AV: E=Sophos;i="4.87,638,1363129200"; d="scan'208";a="13651819" Received: from mail-wi0-f172.google.com ([209.85.212.172]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 09 May 2013 02:57:46 +0200 Received: by mail-wi0-f172.google.com with SMTP id hm14so5649216wib.11 for ; Wed, 08 May 2013 17:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:content-transfer-encoding; bh=s0BK04gTRsXDaV7EuTdZSNWx0dq9uBe5ZmVbR73B/10=; b=vD8G10uGdil2CRaTwGAc4ufxJJ8s4FGMV7h6Kzd5MiaVePAt3uhpr1uVqLe1oOQJJT KEllptAaC/odbS+k14IraK8+JVAnUJ+09jf5zMiEi632KWV9gpEESdFpYZZB2PEcCN2S iCWne8fTtDT9eC+PB1f4CO/5Muiky0LDd3AVAhROdiZso7VGEOikkblegM+T+XNPwcSc m42mDptaqL7ygvM+rLgOmBsfVAu352YE3AW7e1W9F3tOOFcudOBCQRyxU1lgqlg5222X zbesbDFMGbVy5Ff6kFswnNq48GIDSh0bFsLo4FX394Y0cU00SOPTvH3Q01mtehP4gnkJ yjzg== MIME-Version: 1.0 X-Received: by 10.180.72.227 with SMTP id g3mr30548888wiv.1.1368061066324; Wed, 08 May 2013 17:57:46 -0700 (PDT) Received: by 10.194.46.9 with HTTP; Wed, 8 May 2013 17:57:46 -0700 (PDT) In-Reply-To: References: Date: Wed, 8 May 2013 20:57:46 -0400 Message-ID: From: Markus Mottl To: =?ISO-8859-2?Q?Milan_Stanojevi=E6?= Cc: Caml List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] an issue with coercing private types On Wed, May 8, 2013 at 7:34 PM, Milan Stanojevi=C4=87 w= rote: > but this compiles fine > let to_int a =3D (a : 'a Foo.t :> int) This seems like the preferred solution and should always work, because it enforces that "a" has a coercible type (rather than e.g. a mere type variable) by the time type inference reaches the coercion operator. Otherwise it may depend on the order in which the type of sub-terms is inferred whether coercion will work. > and gives me the right type. > > What is wrong with the first version of [to_int]? Is this a bug in the > compiler? I'm using ocaml 4.0.1 > > I also tried this with Foo.t that doesn't have phantom type variable > and in that case both versions of [to_int] work. I'm actually surprised that removing the phantom type variable makes a difference in that respect. I guess this just shows how unpredictable the order of type inference can be, hence the need for proper type annotations with coercions. Regards, Markus -- Markus Mottl http://www.ocaml.info markus.mottl@gmail.com