From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 3AD1D7FC18 for ; Mon, 16 Feb 2015 01:09:24 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of jeansaintremy@yahoo.com) identity=pra; client-ip=98.138.121.71; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jeansaintremy@yahoo.com"; x-sender="jeansaintremy@yahoo.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of jeansaintremy@yahoo.com designates 98.138.121.71 as permitted sender) identity=mailfrom; client-ip=98.138.121.71; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jeansaintremy@yahoo.com"; x-sender="jeansaintremy@yahoo.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@nm45-vm7.bullet.mail.ne1.yahoo.com) identity=helo; client-ip=98.138.121.71; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jeansaintremy@yahoo.com"; x-sender="postmaster@nm45-vm7.bullet.mail.ne1.yahoo.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0A+AgBPNOFUlEd5imJcggY9gRVagwOuKoEzj1SFeYEOB0MBAQEBAQEQAQEBAQcLCwkSMIQeGAQEFQE5FS4ZAjEBDgEGDAyIKwEBAhGmLo9IgWsEgnOBcYlFASMDASMDhVABAQgBAQEBAQEWBgwCAY5+OAKDIYFCBYgykD0FgROFNx8CWop0T4QQb4ELgTgBAQE X-IPAS-Result: A0A+AgBPNOFUlEd5imJcggY9gRVagwOuKoEzj1SFeYEOB0MBAQEBAQEQAQEBAQcLCwkSMIQeGAQEFQE5FS4ZAjEBDgEGDAyIKwEBAhGmLo9IgWsEgnOBcYlFASMDASMDhVABAQgBAQEBAQEWBgwCAY5+OAKDIYFCBYgykD0FgROFNx8CWop0T4QQb4ELgTgBAQE X-IronPort-AV: E=Sophos;i="5.09,583,1418079600"; d="scan'208,217";a="121863927" Received: from nm45-vm7.bullet.mail.ne1.yahoo.com ([98.138.121.71]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 16 Feb 2015 01:09:22 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1424045361; bh=FkvEAi8rf7eYwk47kMND2ABncJtfJCiXao5bnqp+W2c=; h=Date:From:Reply-To:To:Subject:From:Subject; b=WEB2k/X45QFPUc6S+rl0osKgKJOIYl8oSANfkyrSr+H4xxqEQ54jyw/YwIT+boQ62vx+gUgXSBEaAa20PpNZYzKTsBfkSRqKDOIEF7HbH25b7vVEshHHX3kuQIp7Q+mXROJB46jpHaCJWsW8gRe4SRUy/UOyD1EecRI0yitOSABG9LjitfiWZ1+CZS6PJabTvrV1u00957p+VnYogFsPWgrsF2g8bmbkf1Q0TdnOAQS6rbu73gQlb8qGGbHEar3Z8swh3qkIHNRduI5bsGjMsXxYFIGgK9+FXX1idjiOy7HeqZ9BAfXj3atPTNEEnNSWw/m5N3pcNqvhYUhVSmP09A== Received: from [127.0.0.1] by nm45.bullet.mail.ne1.yahoo.com with NNFMP; 16 Feb 2015 00:09:21 -0000 Received: from [98.138.100.111] by nm45.bullet.mail.ne1.yahoo.com with NNFMP; 16 Feb 2015 00:06:33 -0000 Received: from [98.139.212.151] by tm100.bullet.mail.ne1.yahoo.com with NNFMP; 16 Feb 2015 00:06:33 -0000 Received: from [98.139.212.229] by tm8.bullet.mail.bf1.yahoo.com with NNFMP; 16 Feb 2015 00:06:33 -0000 Received: from [127.0.0.1] by omp1038.mail.bf1.yahoo.com with NNFMP; 16 Feb 2015 00:06:33 -0000 X-Yahoo-Newman-Property: ymail-4 X-Yahoo-Newman-Id: 681890.73333.bm@omp1038.mail.bf1.yahoo.com X-YMail-OSG: .A3N8W8VM1n6sOb.6AmpECMTxfC3rQBVI1Ge3Yu6_wt4_ZGQ_6egkMpcUzZJ3AB oUTNYeCUIr_wvK1B4_zL7CdMhT43iqABMMVTdh.21Pu3XfJp9B8IDgPjA4Y5xxlOOxPI6y2dPNjX f2tQHUQ5toX70umRODgDJeJ2LfNrwaxfptO1jCCU0rW4PaSa1Xq34F3JarUQPldumrvdIIk9m.Le xi0GLUJdaowbYMpOUkFt8.cUvqlHQxicDNdOSVyepjUd8GNUZvh2GMhcy.YU9Xc22lYyiofHU4MJ UPwGCRddNJOtfdYGxwJ5TwB8xcHNCVakcSylSV.tOPadnYeozfexRW.RqXrRls0NINyKdavPd6Ip .Zf5BysP9.JqdEmGt1v8db5jOAioTvaIHDbeHSZq6JfLnfydkbvS16DXqeSqC4zRDpdt5e9Jzp_B .NKgQyzt1dibahFuHYTt04Ywu7dkDTksgJQAcpOFgNAQ4QVmHdLwRBIc2vgONiJrqNbpfHCp5wNJ Wv76VeQ.SHimSlAsp24v4Xqv4RdLktvKGcCvJQcfbi2G20LY13zaEUacdC24d_YBev7rWu5c3mRG ktsI6EsUT.Sw- Received: by 76.13.26.110; Mon, 16 Feb 2015 00:06:33 +0000 Date: Mon, 16 Feb 2015 00:06:32 +0000 (UTC) From: Jean Saint-Remy Reply-To: Jean Saint-Remy To: "caml-list@inria.fr" Message-ID: <419599633.6386715.1424045192831.JavaMail.yahoo@mail.yahoo.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_6386714_1742873794.1424045192827" Subject: [Caml-list] explicit polymorphic types in record fields ------=_Part_6386714_1742873794.1424045192827 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, I was reading the ocaml manual section 1.5 where an explicit polymorphic ty= pe can be declared.=C2=A0 I wanted to know if the trailing dot '.' is a spe= cial case "marker" only and does not have anything to do with how we distin= guish floating point multiplication, division, subtraction, and addition, a= nd nothing to do with accessing the elements of an array. Without the trail= ing dot we cannot declare any such polymorphic fields no how, no way. I was= also surprised to find this was possible. [The manual says] In some special cases, you may need to store a polymorphi= c function ina data structure, keeping its polymorphism. Without user-provi= dedtype annotations, this is not allowed, as polymorphism is onlyintroduced= on a global level. However, you can give explicitlypolymorphic types to re= cord fields.# type idref =3D { mutable id: 'a. 'a -> 'a };; type idref =3D { mutable id : 'a. 'a -> 'a; } # let r =3D {id =3D fun x -> x};; val r : idref =3D {id =3D } # let g s =3D (s.id 1, s.id true);; val g : idref -> int * bool =3D # r.id <- (fun x -> print_string "called id\n"; x);; - : unit =3D () # g r;; called id called id - : int * bool =3D (1, true) I am having difficulty reading the first line, the type declaration "type i= dref =3D { mutable id : 'a. 'a -> 'a } ;;"=C2=A0 When I look at the way we = are accessing the field values on line 3, it does look like accessing membe= r fields in other languages and it does superficially resemble array indexi= ng as in "let str =3D "abcdef" ;; str.[1] ;; -: char =3D 'b'".=C2=A0 The tw= o ways we are using the dot '.' are very distinct. Is that correct? The sec= ond is the common place indexing, whereas the first is just a "marker".=C2= =A0 I could not declare the fields for example as a polymorphic tuple for i= nstance: "type idref =3D { mutable 'a * 'b -> 'a }" nor "type idref =3D { m= utable 'a. 'b -> 'a }". The latter is just nonsense, the 'b is undefined. B= ut we could have a two field record by just repeating the type definitions.= "let idref =3D { mutable 'a. 'a -> 'a; mutable 'b. 'b -> 'b }". The polymo= rphic type does not have any restriction, it appears we could have any fund= amental type we wanted. The type 'a variable must be repeated, it is not en= ough to say "type idref =3D { mutable 'a. -> 'a };;" Is it correct then to = read the declaration in this way: the type 'a polymorphic type as a polymor= phic variable of type 'a. I know it sounds redundant, but that is how I am = reading the syntax. Thank you for clarifying this for me. jean ------=_Part_6386714_1742873794.1424045192827 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

I was reading the ocaml = manual section 1.5 where an explicit polymorphic type can be declared. = ; I wanted to know if the trailing dot '.' is a special case "marker" only = and does not have anything to do with how we distinguish floating point mul= tiplication, division, subtraction, and addition, and nothing to do with ac= cessing the elements of an array. Without the trailing dot we cannot declar= e any such polymorphic fields no how, no way. I was also surprised to find = this was possible.

[The manual says] In some special cases, you may need to store a = polymorphic function in a data structure, keeping its polymorphism. Without user-provided type annotations, this is not allowed, as polymorphism is only introduced on a global level. However, you can give explicitly polymorphic types to record fields.
# type idref =3D =
{ mutable id: 'a. 'a -> 'a };;
type idref =3D { mutable id : =
'a. 'a -> 'a; }

# let r =3D {id =
=3D fun x -> x};;
val r : idref =3D {id =3D <=
fun>}

# let g s =3D (s.=
id 1, s.id true);;
val g : idref -> int * bool=
 =3D <fun>

# r.id <- (fun=
 x -> print_string "called id\n"; x);;
- : unit =3D ()

# g r;;
called id
called id
- : int * bool =3D (1, true)
I am having difficulty reading the first line, the type d= eclaration "type idref =3D { mutable id : 'a. 'a -> 'a } ;;"  When = I look at the way we are accessing the field values on line 3, it does look= like accessing member fields in other languages and it does superficially = resemble array indexing as in "let str =3D "abcdef" ;; str.[1] ;; -: char = =3D 'b'".  The two ways we are using the dot '.' are very distinct. Is= that correct? The second is the common place indexing, whereas the first i= s just a "marker".  I could not declare the fields for example as a po= lymorphic tuple for instance: "type idref =3D { mutable 'a * 'b -> 'a }"= nor "type idref =3D { mutable 'a. 'b -> 'a }". The latter is just nonse= nse, the 'b is undefined. But we could have a two field record by just repe= ating the type definitions. "let idref =3D { mutable 'a. 'a -> 'a; mutab= le 'b. 'b -> 'b }". The polymorphic type does not have any restriction, = it appears we could have any fundamental type we wanted. The type 'a variab= le must be repeated, it is not enough to say "type idref =3D { mutable 'a. = -> 'a };;" Is it correct then to read the declaration in this way: the t= ype 'a polymorphic type as a polymorphic variable of type 'a. I know it sou= nds redundant, but that is how I am reading the syntax.

<= div id=3D"yui_3_16_0_1_1424042201418_4329" style=3D"" class=3D"" dir=3D"ltr= ">Thank you for clarifying this for me.

jean
= ------=_Part_6386714_1742873794.1424045192827--