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 IAA19068; Fri, 10 Jan 2003 08:43:33 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id IAA19169 for ; Fri, 10 Jan 2003 08:43:32 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (host59-68.pool80116.interbusiness.it [80.116.68.59]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h0A7hVr12584 for ; Fri, 10 Jan 2003 08:43:31 +0100 (MET) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 662E327249 for ; Fri, 10 Jan 2003 08:45:42 +0100 (CET) Message-ID: <3E1E7A26.301@baretta.com> Date: Fri, 10 Jan 2003 08:45:42 +0100 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826 X-Accept-Language: it, en MIME-Version: 1.0 To: Ocaml Subject: Re: [Caml-list] record declaration, SML References: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk brogoff@speakeasy.net wrote: > On Fri, 10 Jan 2003, Alessandro Baretta wrote: >>So, in order to define just one value one needs to define an >>entire class as in the following example. >> >>class f_one = object method f = 1 end >>let res = C (new f_one) > > > Is this such a big problem? I imagine we're more likely to provide a > smart constructor for t, something like > > let mkC o = C(o :> < f : int >) No, it's not a bit problem. I was just wondering > and just stuff any object with method f : int in there. If we only want there > to be one kind of thing, we're better off using a record. Of course, Daniel > doesn't have that option since he is discussing a syntactic transformation > from SML records into OCaml constructs, and hence using the class system makes > sense on account of the differences between SML record typing and that of > OCaml. Besides, Daniel showed us that you can actually define a record on the fly without cluttering the class namespace. let module M = struct class a = object val f = 1 method f = f end end in C (new M.a) This raises one more question: let module P = struct type t = { f : int } let x = { f = 1 } end in P.x;; The above is not valid Ocaml because P.x has a type which escapes its scope. This is quite evident. Now I would expect Daniel's code to be rejected by the same standards, but it is not. Why? Does class a not escape its scope? > >>BTW, why is something like the above not in the language? It >>seems only natural to have such a feature since an analogous >>construct exists for structs. > > > There are no anonymous records (like SML has) either, so if you see classes as > analogous to records rather than structs it doesn't seem so unnatural. No, I > realize that's not a real explanation. Right. Even unnamed records are missing. But it's different because the Ocaml type system does not support record subtyping--even if record type b in module B defines all fields of record type a in module A with the same types, B is not a subtype of A. On the other hand, object subtyping exists already in the language, so on-the-fly definitions of objects à la façon de Daniel are more meaningful and useful. Alex ------------------- 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