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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id C366A7EC41 for ; Sat, 20 Oct 2012 11:16:46 +0200 (CEST) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.223.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.223.182 as permitted sender) identity=mailfrom; client-ip=209.85.223.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ie0-f182.google.com) identity=helo; client-ip=209.85.223.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-ie0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApcBADdrglDRVd+2m2dsb2JhbABErwyReQgjAQEBAQEICQsJFCeCIAEBAQMBEgITGQEbEgsBAwELBgULDQ0hIQEBEQEFAQoSBhMICgkHh08BAwkGC50rCQOMKIJ2hFEKGScDClmIdQEFDIpmaIZvA5QZgVWBF4oRgy8WKYQT X-IronPort-AV: E=Sophos;i="4.80,621,1344204000"; d="scan'208";a="178115616" Received: from mail-ie0-f182.google.com ([209.85.223.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 20 Oct 2012 11:16:46 +0200 Received: by mail-ie0-f182.google.com with SMTP id k10so3087203iea.27 for ; Sat, 20 Oct 2012 02:16:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=FLNvEm+Uue7fpa6nrn+DbUZyUzo2FMgbnZhaUFGd6MA=; b=wlEkOFib0GEAJExABxHGZY+rzY6avZXmY90RL58QwK1+jfa8pmTKgD2W8D72MNma5s h24Mn3wJkYt+hRbY8sPBx4evnCwaV8+FKCIw3386Da+q32hsgsVIheK7BJopLoKbKtM/ GGq3Gao1ncNGo3ecRHzcfah5d7mHQ/3KLxOx8SRFLp9ZFGeLCHtxmfqqYrOEX8r4gqUv n+iE1HoNUMjpE6RD9r4pRfFuBQ0qsOGIn/a2Ft7AC9PvT9xBpYb/hx7k0Dezbd1CTW3G g9AY2SXpzmTzWnRtDhP4KrImlHjO5TiOjak7/3ZBO5F+Xcyu1OHh0EbcatJXL78VpPvy HgyA== Received: by 10.50.88.233 with SMTP id bj9mr3868374igb.70.1350724604714; Sat, 20 Oct 2012 02:16:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.65.9 with HTTP; Sat, 20 Oct 2012 02:16:04 -0700 (PDT) In-Reply-To: References: From: Gabriel Scherer Date: Sat, 20 Oct 2012 11:16:04 +0200 Message-ID: To: Jeremy Yallop Cc: Yaron Minsky , caml-list@inria.fr, Stephen Weeks , David Powers , Nathan Linger Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] A confusing example with modules and polymorphic variants > I don't see how to make that work in your case, though, because of the nature > of the polymorphism -- i.e. it's based on a row variable rather than a > standard type variable, and there isn't any syntax for quantifying it. You can capture the whole type "as" the polymorphic variable. type s = { z : 'a . [< `Foo ] as 'a } module type S = sig val z : [< `Foo ] end let f s = let module M : S = struct let z = s.z end in () This is essentially the same as your solution, using a polymorphic field in a record instead of a polymorphic structure item in a first-class module. I'm not exactly sure if/why this would solve or not Yaron's problem, but in any regard I would consider the two solutions equivalent. On Sat, Oct 20, 2012 at 12:10 AM, Jeremy Yallop wrote: > On 19 October 2012 22:18, Yaron Minsky wrote: >> We've been running into some troubles with polymorphic variants, >> modules, and the value restriction, that we're not quite able to >> unravel. Here's a stripped down version of the problem. >> >> module type S = sig >> val z : [< `Foo ] >> end >> >> let f z = >> let module M : S = struct let z = z end in () > > I believe the problem here is the monomorphic parameter restriction: the type > of S requires the field z to be polymorphic, but type inference only assigns > monomorhpic types to function parameters. That is, your example doesn't type > check for essentially the same reason that the following code doesn't type > check: > > type s = { > z : 'a. 'a -> 'a > } > > let f z = > let s = { > z = z > } in > () > > One way to work around the monomorphic parameter assumption is to wrap the > parameter in a record with a polymorphic field. > > type z_type = { field : 'a. 'a -> 'a} > > let f z = > let s = { > z = z.field > } in > () > > The parameter is still assigned a monomorphic type (z_type), but the projected > field is polymorphic, as required. > > I don't see how to make that work in your case, though, because of the nature > of the polymorphism -- i.e. it's based on a row variable rather than a > standard type variable, and there isn't any syntax for quantifying it. > > However, you *can* modify your example so that it passes type checking by > wrapping the argument in a first-class module, since module fields can be > row-polymorphic. The easiest way in the cut-down example is to reuse the > signature you already have: > > module type S = sig > val z : [< `Foo ] > end > > let f (module Z : S) = > let module M : S = > struct > let z = Z.z > end > in () > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs