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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 0F54F7FBCE for ; Tue, 13 Jan 2015 21:33:14 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of lpw25@cam.ac.uk) identity=pra; client-ip=131.111.8.150; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="lpw25@cam.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of lpw25@cam.ac.uk) identity=mailfrom; client-ip=131.111.8.150; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="lpw25@cam.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@ppsw-50.csi.cam.ac.uk) identity=helo; client-ip=131.111.8.150; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="postmaster@ppsw-50.csi.cam.ac.uk"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgIBAJKAtVSDbwiWnGdsb2JhbABbg1hYs0sGkkOFcQKBG0MBAQEBAREBAQEBAQYNCQkULoQNAQQBJ0sHBQsLISUPAQQNPBOIGAMJCAQJy30NRYMeDAEfhgWHSoIqB4QpBZIHhASBRIEPMIR8hV2FZIQQbwGCQgEBAQ X-IPAS-Result: AgIBAJKAtVSDbwiWnGdsb2JhbABbg1hYs0sGkkOFcQKBG0MBAQEBAREBAQEBAQYNCQkULoQNAQQBJ0sHBQsLISUPAQQNPBOIGAMJCAQJy30NRYMeDAEfhgWHSoIqB4QpBZIHhASBRIEPMIR8hV2FZIQQbwGCQgEBAQ X-IronPort-AV: E=Sophos;i="5.07,751,1413237600"; d="scan'208";a="96308491" Received: from ppsw-50.csi.cam.ac.uk ([131.111.8.150]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 13 Jan 2015 21:33:13 +0100 X-Cam-AntiVirus: no malware found X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Received: from host86-190-253-80.range86-190.btcentralplus.com ([86.190.253.80]:33784 helo=study.localdomain) by ppsw-50.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.158]:587) with esmtpsa (PLAIN:lpw25) (TLSv1.2:AES128-GCM-SHA256:128) id 1YB89I-00072x-r8 (Exim 4.82_3-c0e5623) (return-path ); Tue, 13 Jan 2015 20:33:12 +0000 From: Leo White To: Thomas Braibant Cc: OCaML Mailing List References: X-Face: "XWxb[u_Z\PA_Y?9@|IA!!+jTb(/290-*ea/Un$I0B98.$n%eL.;2w*,z]WR#T:,p[ NBd++M7l]#7zj7!{~iw $W-"/=|dVjhT[D{4~gE}gK<2`.6fs!;uqqud]vs2N/3^m7{aS1V, Date: Tue, 13 Jan 2015 20:51:03 +0000 In-Reply-To: (Thomas Braibant's message of "Tue, 13 Jan 2015 18:09:54 +0100") Message-ID: <877fwqqua0.fsf@study.localdomain> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Caml-list] Quizz Hi, In OCaml 4.01 and earlier, first-class modules were typed nominatively. In other words, their type was based on the name of the module type used, not its structure. For example: OCaml version 4.01.0 # module type T = sig type t end;; module type T = sig type t end # module type S = sig type t end;; module type S = sig type t end # let f (x : (module T)) : (module S) = x;; Characters 38-39: let f (x : (module T)) : (module S) = x;; ^ Error: This expression has type (module T) but an expression was expected of type (module S) This obviously requires that the module type has a name: # type t = (module sig type t end);; Characters 17-20: type t = (module sig type t end);; ^^^ Error: Syntax error In version 4.02, the type-checking of first-class modules was changed to be structural instead of nominative: OCaml version 4.02.1 # module type T = sig type t end;; module type T = sig type t end # module type S = sig type t end;; module type S = sig type t end # let f (x : (module T)) : (module S) = x;; val f : (module T) -> (module S) = This means that it would now be possible to support first-class modules for types which have no name, but such support has not yet been added. (There are some awkward issues around the syntax in relation to with constraints, but they are probably solvable.) So, in summary, you can't do that, but it is now at least theoretically something you could do. Regards, Leo Thomas Braibant writes: > Hi list, > > Here is a quizz that can easily be solved using OCaml (version > 4.02.1), but it would be less fun than trying to infer which functions > are accepted. > > ``` > module type S = sig val test : 'a list end > > type t = (module S) > > let a (x : t) = > let module M = (val x) in > List.length M.test > > let b (module M : S) = > List.length M.test > > let c ((module M) : t) = > List.length M.test > > let d (module M : t) = > List.length M.test > > let e (x : (module S)) = > let module M = (val x) in > List.length M.test > > let f ((module M) : (module S)) = > List.length M.test > > let g : (module S) -> int = fun (module M) -> > List.length M.test > > let h ((module M) : (module sig val test : 'a list end)) = > List.length M.test > > ``` > (I am sure I have missed interesting variations, though.) > > I have read through > > http://caml.inria.fr/pub/docs/manual-ocaml/types.html, > http://caml.inria.fr/pub/docs/manual-ocaml/modtypes.html > http://caml.inria.fr/pub/docs/manual-ocaml/extn.html#sec230 > > but what I do not get is how to make a variation of `h` work. That is, > I would like to inline the module signature. Is that possible? > > Best, > Thomas