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 2A2FE7FACB for ; Sat, 23 Aug 2014 17:40:19 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of yallop@gmail.com) identity=pra; client-ip=209.85.212.169; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of yallop@gmail.com designates 209.85.212.169 as permitted sender) identity=mailfrom; client-ip=209.85.212.169; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@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-f169.google.com) identity=helo; client-ip=209.85.212.169; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="postmaster@mail-wi0-f169.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am4BAJ61+FPRVdSpm2dsb2JhbABZhDcEgnjRMgF/CBYQAQEBAQEGCwsJFCmEBAEBBBIRBBkBGx0BAwwGBQsNAgImAgIiAREBBQEcBhMiiAsBAxGjVmuLK4FygxCJTQoZJw1mhDwRAQUOgR6NbTMHgnmBUwWcSZMaGCmFEDwvgk8BAQE X-IPAS-Result: Am4BAJ61+FPRVdSpm2dsb2JhbABZhDcEgnjRMgF/CBYQAQEBAQEGCwsJFCmEBAEBBBIRBBkBGx0BAwwGBQsNAgImAgIiAREBBQEcBhMiiAsBAxGjVmuLK4FygxCJTQoZJw1mhDwRAQUOgR6NbTMHgnmBUwWcSZMaGCmFEDwvgk8BAQE X-IronPort-AV: E=Sophos;i="5.04,386,1406584800"; d="scan'208";a="76169574" Received: from mail-wi0-f169.google.com ([209.85.212.169]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 23 Aug 2014 17:40:17 +0200 Received: by mail-wi0-f169.google.com with SMTP id n3so2079661wiv.0 for ; Sat, 23 Aug 2014 08:40:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=/lzyziwUHia+zvXggk1M8S3iRZBrm2d4mBIQcq5yoVc=; b=dSaYzksoRdHn/O8ME8mtkiYa4rk0iBjrzMTUqkBQCcMgfKuuuDJQdONhRyEcr40kBs x2VKDQ8f/YLl3SnwlX0iGoPGkr3ql73CXAnFtYva7SKAxaPxTdNHEo40AtG54BABlJW5 Xn9XLC/CpC7j9KTz0I4fj0GKY3J7lTU7UPTusDbqfr3Yf34W+ZOtBYhOFy0oEF4oOwAi mv1RDVXgUrtT+i1pT6t6PTKYSgNDhSQ0OsOfxqzbquE+dTjNtbZM9HrrEDTzSyLi4bYS WwVMzXkZlRjUotCzoaJHQJM1GP0bGx/SxDM+yj2ZSbs3XuFQWPeA3Owh9rnQVZSZ4Ysl /zFA== MIME-Version: 1.0 X-Received: by 10.194.80.71 with SMTP id p7mr11605137wjx.21.1408808417102; Sat, 23 Aug 2014 08:40:17 -0700 (PDT) Received: by 10.217.131.18 with HTTP; Sat, 23 Aug 2014 08:40:17 -0700 (PDT) In-Reply-To: <83ADBE14262643EA9519BBE719987901@erratique.ch> References: <4060AF3441F149839C46804E64E2B9CE@erratique.ch> <83ADBE14262643EA9519BBE719987901@erratique.ch> Date: Sat, 23 Aug 2014 16:40:17 +0100 Message-ID: From: Jeremy Yallop To: =?UTF-8?Q?Daniel_B=C3=BCnzli?= Cc: Caml-list Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Phantom types and variants On 22 August 2014 04:17, Daniel B=C3=BCnzli w= rote: > Sorry the coerce function type was wrong in my preceding message. Here is= the example: > > ----- > module M : sig > type kind =3D [ `A | `B ] > type +'a t constraint 'a =3D [< kind ] > > val a : unit -> [> `A] t > val b : unit -> [> `B] t > val coerce : ([< kind] as 'a) -> 'b t -> 'a t > end =3D struct > type kind =3D [ `A | `B ] > type +'a t =3D > { kind : kind } > constraint 'a =3D [< kind] > > let a () =3D { kind =3D `A } > let b () =3D { kind =3D `B } > let coerce k v =3D if v.kind <> k then invalid_arg "" else v > end The following definition does the trick (and avoids the allocation): let coerce (#kind as k) ({kind} as v) =3D if v.kind <> k then invalid_arg "" else v