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=1.4 required=5.0 tests=SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 7B097BC69 for ; Sat, 24 Feb 2007 14:33:13 +0100 (CET) Received: from mu-out-0910.google.com (mu-out-0910.google.com [209.85.134.188]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1ODXCZ9030196 for ; Sat, 24 Feb 2007 14:33:13 +0100 Received: by mu-out-0910.google.com with SMTP id w9so705610mue for ; Sat, 24 Feb 2007 05:33:12 -0800 (PST) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Q3SCCDvbDra/u3dmMf2UeI53+0v6rvfaka+qXOx1qrWTAudv+9EQfQozEIuIWWTOzSPXeVUvCESItK42PAwQYaoT80Tg9Csgm7WpHmBVb4sXLuDXai1La3vuZeHsxZE1O1ptV3KALS/SddATCn9iH4jXw07GDy8auJnlAyhHaII= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=KzKDQQOoN8iI6uP/Khjn/fDsqyO8c/C0ny8av/g8F7KMezBaIFPHvfdqEHmjjr11BtLzkiC3ctxHodXa8hay3yQAt55HYXvn3LCPoExRp+DlxuteYjMPCO6llXDNp+Hg420EWOGvduw9NrsoKWNywZsHI1XAZb2yeclNJBTxOyg= Received: by 10.82.175.2 with SMTP id x2mr1036502bue.1172323992388; Sat, 24 Feb 2007 05:33:12 -0800 (PST) Received: by 10.82.134.14 with HTTP; Sat, 24 Feb 2007 05:33:12 -0800 (PST) Message-ID: <4a708d20702240533r573a1d1w218d5ae4bde8c814@mail.gmail.com> Date: Sat, 24 Feb 2007 14:33:12 +0100 From: "Lukasz Stafiniak" To: "caml users" Subject: [Caml-list] Instruction selection in the OCaml compiler: Modulesor classes? In-Reply-To: <4a708d20702240518l2c430b06r18fe64cabe5cbe9@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <6CB0D237-F894-4AC3-BDBE-2BB484928D3C@gmail.com> <007401c75780$c87c53d0$15b2a8c0@wiko> <1172285488.23720.53.camel@rosella.wigram> <53c655920702240348s756a662fv12c1f53c972ed67e@mail.gmail.com> <4a708d20702240518l2c430b06r18fe64cabe5cbe9@mail.gmail.com> X-j-chkmail-Score: MSGID : 45E03E98.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 45E03E98.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; lukasz:01 ocaml:01 compiler:01 functor:01 functor:01 ocaml:01 rwh:01 orderedtype:01 sig:01 val:01 elt:01 orderedtype:01 sig:01 val:01 elt:01 [I'm sorry, I forgot to send to the list!] On 2/24/07, David Baelde wrote: > On 2/24/07, skaller wrote: > > 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. If we really had structural typing that name would > > simply be an alias. Why can't we eliminate that name? *** > > One worthy remark here might be that side-effects can occur at functor > instantiation. Then, forcing the user to think about when the > instantiation occurs is useful... > Yet OCaml already has trouble with some nasty patterns of effects at functor instantiation. Taken from one of the slides at http://www.cs.cmu.edu/~rwh/courses/modules/ This is good (Skaller: does it solve your problem?): module type DICT = functor (Key : Set.OrderedType) -> sig type 'a dict val domain : 'a dict -> Set.Make(Key).t end;; module type PRIO_QUEUE = functor (Elt : Set.OrderedType) -> sig type queue val contents : queue -> Set.Make(Elt).t end;; module QueuedDict (Data : Set.OrderedType) (MyDict : DICT) (MyPrioQueue : PRIO_QUEUE) = struct module Dict = MyDict (Data) module PQ = MyPrioQueue (Data) module DataSet = Set.Make (Data) let queued_domain dict pq = DataSet.equal (Dict.domain dict) (PQ.contents pq) end;; This is bad: let moonFull = let v = ref false in fun () -> v := not !v; !v ;; module type S = sig type t val x : t val f : t -> t val g : t -> t -> bool end;; module Weird (Top : sig end) = (struct type t = int let x = if moonFull () then 1 else 2 let f x = x + 2 let g x y = (3*x + 2*y) / (x - y + 1) = 7 end : S);; module Gen (X : functor (Top : sig end) -> S) = X (struct end);; module W1 = Gen (Weird);; (* moon full now *) module W2 = Gen (Weird);; (* moon no longer full now *) W1.g W1.x W2.x;;