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 6BAAB7F8FC for ; Tue, 10 Jun 2014 11:25:26 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.15.14; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=mailfrom; client-ip=212.227.15.14; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.web.de) identity=helo; client-ip=212.227.15.14; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoQBAILOllPU4w8OnGdsb2JhbABZyDUBgQ4WDwEBAQEBBg0JCRQohAMBAQQBOkQLCxgJJQ8FKIhhAQwMxHUfhX8XjnMWgxWBFgSaIIZgEpAS X-IPAS-Result: AoQBAILOllPU4w8OnGdsb2JhbABZyDUBgQ4WDwEBAQEBBg0JCRQohAMBAQQBOkQLCxgJJQ8FKIhhAQwMxHUfhX8XjnMWgxWBFgSaIIZgEpAS X-IronPort-AV: E=Sophos;i="4.98,1008,1392159600"; d="scan'208";a="66526076" Received: from mout.web.de ([212.227.15.14]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 10 Jun 2014 11:25:25 +0200 Received: from frosties.localnet ([78.43.112.61]) by smtp.web.de (mrweb004) with ESMTPSA (Nemesis) id 0MB06e-1X21Y03HWu-009wtA for ; Tue, 10 Jun 2014 11:25:25 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.82) (envelope-from ) id 1WuIJ2-0000AF-1k for caml-list@inria.fr; Tue, 10 Jun 2014 11:25:24 +0200 Date: Tue, 10 Jun 2014 11:25:23 +0200 From: Goswin von Brederlow To: caml-list@inria.fr Message-ID: <20140610092523.GB31598@frosties> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Provags-ID: V03:K0:YlQYNOD/Qce3gzMbuM4NcHVys4ohNzeoLWakWzukt5RFylZV7RZ wTCn9B+8EUIRfNGiKLK284OqaWpa4OdFyDDa+SIrxb9ewI9XZGyCsbNIp/0QlTGOGNTF8AN 06nc9M2A8OQRFwivjsFm17QL9h2F6wwTKm40V862ktdAleIgHa4IAsAIriVTSBG8iPNLR/I c7mwwSq9St3jMWe5gcS2A== Subject: Re: [Caml-list] Row-polymorphic type declarations On Mon, Jun 09, 2014 at 11:50:22AM -0700, Jordan W wrote: > I'd like to hear the answers to some questions asked on Twitter, that Anil > began replying to: > > The original question was: Does anyone know why OCaml doesn't allow > defining types with polymorphic row variables: or [> `Red ] > but will infer them? > > Anil's answer was to use: > > type 'a t constraint 'a = [> `Red ] > type 'a t constraint 'a = > > Here are the follow up questions that could still use some clarification: > > 1. Does anyone know how can we later instantiate the polymorphic row > variables ".." with particular rows (both for obj methods and variants). > Any good docs on this? How do we assert that another type/expression is > equivalent to 'a t with 'a being a particular set of rows. > > Could someone give an example with a 2D point type > > type 'a twoDimensionalPoint constraint 'a = ;; > > How would we create another type threeDimensionalPoint that we assert is a > two dimensional point with the polymorphic row variables being set to > `z:int`? I understand type inference/checking automates most of this, but I > often like to explicitly write type definitions to verify my own > understanding of the program/inference. I think you can't assert that in the definition of the threeDimensionalPoint type. But you can add a dummy function that takes a threeDimensionalPoint and returns it as a twoDimensionalPoint. If the types can't be unified then the function will give an error. > 3. Also curious why annotations in arguments don't require acknowledgment > of row polymorphism > > let f (o:) = o#x + o#y;; Not sure what you ask there. You are annotating a type. period. > 4. It appears there are two ways to write the row-polymorphic type > annotation: > type 'a t = ([> `Red ] as 'a) and type 'a t constraint 'a = [> `Red ]. Why > are there two ways and what are the advantages? I'm not sure if both are identical and in what cases you can only use the one form or the other. But I think only the constraint syntax can be used when declaring the type of functions. MfG Goswin