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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id C03167F71A for ; Thu, 10 Apr 2014 22:14:36 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of krishnan@cs.bham.ac.uk) identity=pra; client-ip=147.188.128.150; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="krishnan@cs.bham.ac.uk"; x-sender="krishnan@cs.bham.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of krishnan@cs.bham.ac.uk) identity=mailfrom; client-ip=147.188.128.150; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="krishnan@cs.bham.ac.uk"; x-sender="krishnan@cs.bham.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@sun61.bham.ac.uk) identity=helo; client-ip=147.188.128.150; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="krishnan@cs.bham.ac.uk"; x-sender="postmaster@sun61.bham.ac.uk"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8BAFr7RlOTvICWnGdsb2JhbABayWoWDgEBAQEBCAsJCRQoglMRQD0WGAMCAQIBWAYCAQGHeASbD6t6hiOPCYQiAQOfMY8g X-IPAS-Result: Av8BAFr7RlOTvICWnGdsb2JhbABayWoWDgEBAQEBCAsJCRQoglMRQD0WGAMCAQIBWAYCAQGHeASbD6t6hiOPCYQiAQOfMY8g X-IronPort-AV: E=Sophos;i="4.97,835,1389740400"; d="scan'208";a="67565116" Received: from sun61.bham.ac.uk ([147.188.128.150]) by mail2-smtp-roc.national.inria.fr with ESMTP; 10 Apr 2014 22:14:09 +0200 Received: from [147.188.128.127] (helo=bham.ac.uk) by sun61.bham.ac.uk with esmtp (Exim 4.72) (envelope-from ) id 1WYLMP-0006gT-N1 for caml-list@inria.fr; Thu, 10 Apr 2014 21:14:09 +0100 Received: from [92.232.183.83] (helo=[192.168.0.9]) by bham.ac.uk (envelope-from ) with esmtpsa (TLSv1:DHE-RSA-AES128-SHA:128) (Exim 4.82) id 1WYLMO-0002jk-G5 for caml-list@inria.fr using interface auth-smtp.bham.ac.uk; Thu, 10 Apr 2014 21:14:09 +0100 Message-ID: <5346FB8F.3010406@cs.bham.ac.uk> Date: Thu, 10 Apr 2014 21:14:07 +0100 From: Neel Krishnaswami User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BHAM-AUTH-data: TLSv1:DHE-RSA-AES128-SHA:128 via 147.188.128.21:465 (krishnan) X-Validation-by: krishnan@cs.bham.ac.uk Subject: [Caml-list] First class modules question Hello, I'm experimenting with Ocaml's first-class modules feature, and have run into a problem. I have a record type type 'a monoid = {unit : 'a; join : 'a -> 'a -> 'a} and a signature module type APPLICATIVE = 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 and I would like to write a function which turns a monoid into an applicative module, as follows: let monoid_to_app (type s) (m : s monoid) = let module I = struct type 'a t = s let map _ x = x let pure _ = m.unit let ($) x y = m.join x y end in (module I : APPLICATIVE with type 'a t = s) 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 package-type ::= modtype-path | modtype-path with package-constraint {and package-constraint} package-constraint ::= type typeconstr = typexpr This does not permit a constraint of the form "type 'a t = s", unlike the module-constraint production of the grammar. Is this a fundamental limitation on first-class modules, or is it just a restriction for ease of implementation? -- Neel Krishnaswami N.Krishnaswami@cs.bham.ac.uk