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 B4BC67F71A for ; Thu, 10 Apr 2014 23:16:10 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of info@gerd-stolpmann.de) identity=pra; client-ip=212.227.126.187; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="info@gerd-stolpmann.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of info@gerd-stolpmann.de) identity=mailfrom; client-ip=212.227.126.187; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="info@gerd-stolpmann.de"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of postmaster@moutng.kundenserver.de designates 212.227.126.187 as permitted sender) identity=helo; client-ip=212.227.126.187; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="postmaster@moutng.kundenserver.de"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkACAGoJR1PU4367lGdsb2JhbABaDoMzg2XBIYEkFg4BAQEBBwsLCRIqgiUBAQEDASMEUgULCw40AgJXBhMJh2sMCaoSomUXiSiFHiYHgm+BSQSPMYpihRkFjl9C X-IPAS-Result: AkACAGoJR1PU4367lGdsb2JhbABaDoMzg2XBIYEkFg4BAQEBBwsLCRIqgiUBAQEDASMEUgULCw40AgJXBhMJh2sMCaoSomUXiSiFHiYHgm+BSQSPMYpihRkFjl9C X-IronPort-AV: E=Sophos;i="4.97,836,1389740400"; d="asc'?scan'208";a="67571596" Received: from moutng.kundenserver.de ([212.227.126.187]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 10 Apr 2014 23:16:10 +0200 Received: from office1.lan.sumadev.de (dslb-178-004-065-051.pools.arcor-ip.net [178.4.65.51]) by mrelayeu.kundenserver.de (node=mreue007) with ESMTP (Nemesis) id 0MKgZn-1WWRBe0XZ9-001zmd; Thu, 10 Apr 2014 23:16:09 +0200 Received: from [192.168.5.106] (dslb-178-004-065-051.pools.arcor-ip.net [178.4.65.51]) by office1.lan.sumadev.de (Postfix) with ESMTPSA id 8F850DC270; Thu, 10 Apr 2014 23:16:08 +0200 (CEST) Message-ID: <1397164567.4084.24.camel@thinkpad> From: Gerd Stolpmann To: Neel Krishnaswami Cc: caml-list@inria.fr Date: Thu, 10 Apr 2014 23:16:07 +0200 In-Reply-To: <5346FB8F.3010406@cs.bham.ac.uk> References: <5346FB8F.3010406@cs.bham.ac.uk> Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-lA7/XVSXOrWEw5+HYNhx" X-Mailer: Evolution 3.2.3-0ubuntu6 Mime-Version: 1.0 X-Provags-ID: V02:K0:ytUyRlg1LWTp0IDuJgOasaflLRXmB+Om2c3BxwzPZbX jntWcpJJAIylmC+dWW1lBohEVxjjqNQK5p+XP1lNM+H8NAdtAg qqMcgMSZHqvNtQhAUjajSxc26mLUXkITzfJEoJM7OnqvI5S+IB AnXl1dqwlmWbWRDmFnMqbYPa3/6xNQcBaoU/KKafINSs+HAJo1 Om6tIS2BGo0/zTKanMR3YBlzZ7HoXzT3fOA5dtF4Y0vo/D2O5q 1GVEAGs/qRZ2FzRmh/JoKT/sERDQXTT7Fx5fsEnYCaw6goCw2T uEzCoLe6xvqPCXp4GoOSpCYIoBC8l6IjV9dROwBpP1mBQ49X3j hmFtEbP0d1psUSkpZnyirt3hEc2Om3VEx83tDEwdr Subject: Re: [Caml-list] First class modules question --=-lA7/XVSXOrWEw5+HYNhx Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Am Donnerstag, den 10.04.2014, 21:14 +0100 schrieb Neel Krishnaswami: > Hello, >=20 > I'm experimenting with Ocaml's first-class modules feature, and > have run into a problem. I have a record type >=20 > type 'a monoid =3D {unit : 'a; join : 'a -> 'a -> 'a} >=20 > and a signature >=20 > module type APPLICATIVE =3D sig > type 'a t > val map : ('a -> 'b) -> 'a t -> 'b t > val pure : 'a -> 'a t > val ( $ ) : ('a -> 'b) t -> 'a t -> 'b t > end >=20 > and I would like to write a function which turns a monoid into > an applicative module, as follows: But you don't mean the applicative functor feature of OCaml, right? This doesn't work with first class modules. (Just to avoid misunderstandings.) > let monoid_to_app (type s) (m : s monoid) =3D > let module I =3D struct > type 'a t =3D s > let map _ x =3D x > let pure _ =3D m.unit > let ($) x y =3D m.join x y > end > in (module I : APPLICATIVE with type 'a t =3D s) >=20 > Here, I want to constrain the type of APPLICATIVE to be the monoid > element type s. However, Ocaml complains with a syntax error, and > looking at the grammar for type constraints, the annotation on I > is a package-type, which only permits constraints using the > package-constraint production >=20 > package-type ::=3D modtype-path > | modtype-path with package-constraint > {and package-constraint} >=20 > package-constraint ::=3D type typeconstr =3D typexpr >=20 > This does not permit a constraint of the form "type 'a t =3D s", > unlike the module-constraint production of the grammar. >=20 > Is this a fundamental limitation on first-class modules, or is it > just a restriction for ease of implementation? I guess the problem is that it is unclear/unexpressable then what the constraint means for 'a. Imagine you had a constraint type 'a t =3D 'a list. This would implicitly mean that any 'a works on the right side (and thus on the left, too). However, as we don't know anything about the right side, we cannot conclude that in your example. If e.g. the right side were int list, you could read this as a constraint 'a=3Dint. This just means that a parameterized constraint can also constrain the parameter, but we don't have any means to express that. So I guess this is the reason why it is not supported. (You probably need a notation like "type 'a t =3D s where 'a =3D u".) Gerd --=20 ------------------------------------------------------------ Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de Creator of GODI and camlcity.org. Contact details: http://www.camlcity.org/contact.html Company homepage: http://www.gerd-stolpmann.de ------------------------------------------------------------ --=-lA7/XVSXOrWEw5+HYNhx Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQEcBAABAgAGBQJTRwoXAAoJEAaM4b9ZLB5T4foH/jUZ4Hs2c+8mOzwcC5ec8+Gr T+Yj5IifPS9cXtjry6UU+v8ayGDHaNjn/IMnCxgTpQb99UTUpi3OEksTdI5OnLq8 tcoykTjmEBzv/UWeWKtducl8PMCbczIdNMaX6mGzHpI1ffK4PamRRONfzgih+vXc /P6etxxPah6NZgk2qbNt7NrBEHbn0kXOGW1yT7EHKbS6CsKbsKt7kMob/XnzHKLn QlXljfs7nSCZ3rQ/TfmsOMhAUhjnMFfCyOD6Tipn0E20nFIHQ+Ej5em69C8imBMu Vh92MnB8svjcYafiiBULRX5j3gA0KiizUSeb2nVhWNkM8oi9J84qiyErmSoxZ5k= =x6rt -----END PGP SIGNATURE----- --=-lA7/XVSXOrWEw5+HYNhx--