From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id C1624BC69 for ; Sat, 24 Feb 2007 18:39:41 +0100 (CET) Received: from ipmail01.adl2.internode.on.net (ipmail01.adl2.internode.on.net [203.16.214.140]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1OHddq0014843 for ; Sat, 24 Feb 2007 18:39:40 +0100 Received: from ppp41-119.lns2.syd6.internode.on.net (HELO rosella) ([59.167.41.119]) by ipmail01.adl2.internode.on.net with ESMTP; 25 Feb 2007 04:09:37 +1030 X-IronPort-AV: i="4.14,215,1170595800"; d="scan'208"; a="92966295:sNHT22406468" Subject: Re: [Caml-list] Instruction selection in the OCaml compiler:Modulesor classes? From: skaller To: Andreas Rossberg Cc: caml-list@inria.fr In-Reply-To: <00c401c75824$36265fe0$15b2a8c0@wiko> References: <6CB0D237-F894-4AC3-BDBE-2BB484928D3C@gmail.com> <007401c75780$c87c53d0$15b2a8c0@wiko> <1172285488.23720.53.camel@rosella.wigram> <00c401c75824$36265fe0$15b2a8c0@wiko> Content-Type: text/plain Date: Sun, 25 Feb 2007 04:39:34 +1100 Message-Id: <1172338774.5345.21.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 45E0785B.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 compiler:01 0100,:01 rossberg:01 functor:01 functor:01 sig:01 struct:01 struct:01 sig:01 val:01 foo:01 val:01 admittedly:01 stdlib:01 On Sat, 2007-02-24 at 15:58 +0100, Andreas Rossberg wrote: > "skaller" : > > > > It seems like a module functor allows both anonymous > > signatures (structural) and also anonymous argument > > modules (structural), yet you cannot have > > anonymous functor applications: you have to bind the application to > > a module name. > > Not at all. For instance, given > > module Id(X : sig type t end) = X > module A = struct type t = int end > > it is perfectly legal to write: > > module A' = Id(Id(Id(A))) > > Obviosuly, the inner applications of Id are all "anonymous". > > Likewise, you can say > > (3 : Id(Id(A)).t) > > Also purely anonymous applications. I had no idea you could do that! > You can more or less do that already, as long as you introduce a suitable > global module to host the integer type: > > module Int = struct type t = int let compare = compare end > > signature A = sig ... val foo : u -> Set.Make(Int).t -> unit ... end > signature B = sig ... val bar : v -> w -> Set.Make(Int).t ... end > > Admittedly, the type looks a bit ugly, and it would be even nicer if Int was > in the stdlib. But that are merely a questions of library design. [..] > Due to the "weak syntactic notion of module equivalence" I was mentioning > earlier you have to make sure that all these type expressions really refer > to the same Int module. This is a limitation of OCaml's module type system, > and may be what sometimes gives the impression of "nominal" typing. Yes .. I think I see. Two such modules 'Int' would have the same type, but not the same 'identity'. In a similar way that module Int' = struct type t = int let compare = mycompare end has the same type as Int .. but it's a different module because the value of 'compare' member is different. I think what you're saying also explains some of the weird sharing constraints sometimes seen. [When I tried to implement modular functors in Felix I couldn't figure out what was going on and had to give up .. typeclasses were easier, but it's discouraging to find you can only have one total order defined for integers.. :] -- John Skaller Felix, successor to C++: http://felix.sf.net