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 5AF4B7EC41 for ; Sat, 20 Oct 2012 03:34:48 +0200 (CEST) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of yminsky@janestreet.com) identity=pra; client-ip=38.105.200.115; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="yminsky@janestreet.com"; x-sender="yminsky@janestreet.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of yminsky@janestreet.com designates 38.105.200.115 as permitted sender) identity=mailfrom; client-ip=38.105.200.115; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="yminsky@janestreet.com"; x-sender="yminsky@janestreet.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@nyc-dmz-mxout2.janestreet.com) identity=helo; client-ip=38.105.200.115; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="yminsky@janestreet.com"; x-sender="postmaster@nyc-dmz-mxout2.janestreet.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqYBAI/+gVAmachznGdsb2JhbABFwQUrAQEBAQEIFAk7giABAQEEEgITGQEBNwEPCwsNLiEBEgEFARwGEyKHUAMPA51UCQOKa4QzAQWFMg2JTgaKcmiGb5QcgVaLKIMvFimELYF8 X-IronPort-AV: E=Sophos;i="4.80,618,1344204000"; d="scan'208";a="178090664" Received: from mx2.janestreet.com (HELO nyc-dmz-mxout2.janestreet.com) ([38.105.200.115]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 20 Oct 2012 03:34:47 +0200 Received: from nyc-qsv-mail1.delacy.com ([172.25.22.57]) by nyc-dmz-mxout2.janestreet.com with esmtp (Exim 4.76) (envelope-from ) id 1TPNxc-0000PP-VP for caml-list@inria.fr; Fri, 19 Oct 2012 21:34:44 -0400 Received: from nyc-dmz-mxgoog1.delacy.com ([172.25.224.109] helo=mxgoog1.janestreet.com) by nyc-qsv-mail1.delacy.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1TPNxc-0004Vb-Tt for caml-list@inria.fr; Fri, 19 Oct 2012 21:34:44 -0400 Received: from mail-qc0-f198.google.com ([209.85.216.198]) by mxgoog1.janestreet.com with esmtp (Exim 4.76) (envelope-from ) id 1TPNxc-0007L6-S5 for caml-list@inria.fr; Fri, 19 Oct 2012 21:34:44 -0400 Received: by mail-qc0-f198.google.com with SMTP id e13so2375019qcs.9 for ; Fri, 19 Oct 2012 18:34:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=eHNYTdRQUy+Io5ZR+T9fii3rW8iqj7EtkfC+jzehAWc=; b=rPtKViF2LRRUi8FAgctmQQ+QA0v9e8cmD27m+m+3mvLm1+mkY74o+da18oNripID3+ VKq9AnbxYtor7SPwY/Uh/WkwvkUqKYg0uGw17c/+JmaquWsxbA7K1Tmpl/rtkIt6QXgz ZSjEKhLffLjyV9UeCBeL3yQuH3Uep+3xTjkUA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=eHNYTdRQUy+Io5ZR+T9fii3rW8iqj7EtkfC+jzehAWc=; b=AZUcKAFQm+whT0GfWWP0kxsusFQMkEc/byBZI0S1f0JnSKHCKmGmCwsgnUHimDomaa AiCcRgo2fTwONBu+T6XNCqqdQmGbJ8msUn/OwM70BYhPca1oHHmGB49tlrYWIbk7znJP Ig1QfK5kA0hQLF6tjOFmhEOzhj4rpHw1jiy9++97YEM7uIbC3EJzlEZ14Wdojoq8tTzE xbdw4Dd52ocIFP3QcH6pj7EXm1pjC1ujMUb4FI+2U9UjvfTGMC09w4ibnUCazRv9RDVD mBSEX61kbiFq+Eva3LaQuyyE06siNuoOWTrYpRGOiFkScn1mrDDBy5uuv4kGvw4U+iYA Wk6w== Received: by 10.52.90.147 with SMTP id bw19mr3265354vdb.17.1350696884634; Fri, 19 Oct 2012 18:34:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.90.147 with SMTP id bw19mr3265346vdb.17.1350696884410; Fri, 19 Oct 2012 18:34:44 -0700 (PDT) Received: by 10.58.203.225 with HTTP; Fri, 19 Oct 2012 18:34:44 -0700 (PDT) X-Originating-IP: [72.225.238.212] In-Reply-To: References: Date: Fri, 19 Oct 2012 21:34:44 -0400 Message-ID: From: Yaron Minsky To: Jeremy Yallop Cc: caml-list@inria.fr, Stephen Weeks , David Powers , Nathan Linger Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQm/lJYQ11vT+JB4j5/yD9DpMj/4LqBvT45wF1PtWg0WFHaz9LnLbHjVZY4FccUTJsldnvrZHf8hapS12xHahnUbjTlUxpjzjZiQiF2pdOWr+6/jRuxPWguV7yVj56x+9o3nUwjY5L5G8lQyrCA+fSkzYKyQyA== Subject: Re: [Caml-list] A confusing example with modules and polymorphic variants Thanks! That all makes perfect sense, now that you say it. Not sure why it was so hard for me to figure it out on my own. One interesting bit is that a very similar example can be made to work without resorting to these kinds of tricks. In particular, if we change the [< `Foo] to [> `Foo], then, we can get the polymorphism we need back by using a cast: module type S = sig val z : [> `Foo ] end let f z = let module M : S = struct let z = (z : [`Foo] :> [> `Foo]) end in () But this doesn't really help in the case I'm after. y On Fri, Oct 19, 2012 at 6:10 PM, 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 ()