From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA02981; Thu, 28 Nov 2002 21:45:59 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA02134 for ; Thu, 28 Nov 2002 21:45:58 +0100 (MET) Received: from pulsar.univ-valenciennes.fr (pulsar.univ-valenciennes.fr [193.50.192.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gASKjw126833 for ; Thu, 28 Nov 2002 21:45:58 +0100 (MET) Received: from univ-valenciennes.fr (datar3.univ-valenciennes.fr [192.168.6.202]) by pulsar.univ-valenciennes.fr (8.12.3/jtpda-5.4) with SMTP id gASLaEkd194658 ; Thu, 28 Nov 2002 21:36:15 GMT Date: Thu, 28 Nov 2002 21:44:30 +0100 From: Vincent Poirriez To: Vincent Poirriez Cc: caml-list@inria.fr, dorian.petit@univ-valenciennes.fr Subject: [Caml-list] Re: modules and objects Message-Id: <20021128214430.08055948.Vincent.Poirriez@univ-valenciennes.fr > In-Reply-To: <20021128191440.587d1608.Vincent.Poirriez@univ-valenciennes.fr> References: <20021128191440.587d1608.Vincent.Poirriez@univ-valenciennes.fr> X-Mailer: Sylpheed version 0.8.0 (GTK+ 1.2.10; i386-debian-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MailScanner: Found to be clean Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk OK , I was tired,forgive the question. the answer is obvious if for example I remember that types are not first class values and that a module may (and often) contains types. Vincent Le Thu, 28 Nov 2002 19:14:40 +0100 Vincent Poirriez vous avez écrit: |Hello list, | |My non-important question is "why a module is not a first class |value? while objects are." | I was playing with modules and objects, and I found funny that it's |possible to simulate the constructor new, just by using a functor |taking an empty module. | |module Void = struct end |module type Unit = sig end | |module Build(M:Unit) = struct | let r = ref 0 | let get () = !r | let put i = r :=i |end | |module type CONS = sig val get: unit -> int end |module type PROD = sig val put: int -> unit end | |module Foo = Build(Void) |module Bar = Build(Void) |module FooC= (Foo:CONS) |module FooP= (Foo:PROD) | |What remains impossible is: | let lm = [FooP;FooC] impossible | |While with objects: |class build = object |val mutable r = 0 |method get = r |method put i = r <- i |end | |let foo = new build |let bar = new build | |class virtual cons = object | method virtual get : int |end |class virtual prod = object | method virtual put : int -> unit |end |let fooc = (foo :> cons) |let foop = (foo :> prod) | | let lo = [foo;bar] | |Is correct. | |Vincent | | | |-- |courriel: vincent.poirriez@univ-valenciennes.fr |tel: (33)[0]3 27 51 19 53 |Université de Valenciennes et du Hainaut-Cambrésis - Le Mont Houy |F-59313 Valenciennes cedex 9 - FRANCE |http://www.univ-valenciennes.fr/LAMIH/ROI/poirriez -- courriel: vincent.poirriez@univ-valenciennes.fr tel: (33)[0]3 27 51 19 53 Université de Valenciennes et du Hainaut-Cambrésis - Le Mont Houy F-59313 Valenciennes cedex 9 - FRANCE http://www.univ-valenciennes.fr/LAMIH/ROI/poirriez ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners