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 EAA19580; Sun, 14 Jul 2002 04:01:08 +0200 (MET DST) 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 EAA19547 for ; Sun, 14 Jul 2002 04:01:05 +0200 (MET DST) Received: from mbg.sphere.ne.jp (mbg.sphere.ne.jp [210.150.254.179]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g6E214j10718 for ; Sun, 14 Jul 2002 04:01:04 +0200 (MET DST) Received: from localhost (pl886.nas924.o-tokyo.nttpc.ne.jp [61.197.109.118]) by mbg.sphere.ne.jp (Postfix) with ESMTP id B9CBA3A2C2 for ; Sun, 14 Jul 2002 09:58:22 +0900 (JST) To: caml-list@inria.fr Subject: Re: [Caml-list] Five Questions about Objects In-Reply-To: <200207131340.JAA07158@hickory.cc.columbia.edu> References: <200207131340.JAA07158@hickory.cc.columbia.edu> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.1 (AOI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20020714095816B.yoriyuki@mbg.sphere.ne.jp> Date: Sun, 14 Jul 2002 09:58:16 +0900 From: YAMAGATA yoriyuki X-Dispatcher: imput version 991025(IM133) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Oleg Subject: [Caml-list] Five Questions about Objects Date: Sat, 13 Jul 2002 09:42:47 -0400 > let point a b = > object > val x = a > val y = b > method get () = (x, y) > end;; I think You can't do like this. object ... end is a part of a class definition, and not an ordinary expression. However, I wonder why a class is necessary in the first place. I'm not familiar with the theory of OOP, but I feel like direct creation of objects is possible in functional languages. It simplifies the syntax, fits better the concept of functional programming, (I mean the slogan that everything is an expression.) and more powerful. Ok, maybe it does not have much advantage over current approach, but if both can do the same thing, why not use the simpler one? > 4) Can I construct an object that the following function f would accept? > # let f a = a#m1 (); a#b#m2 ();; > val f : < b : < m2 : unit -> 'a; .. >; m1 : unit -> 'b; .. > -> 'a = # class ['b] b (v:'b) = object method m2 () = v end;; class ['a] b : 'a -> object method m2 : unit -> 'a end # class ['a, 'c] a (v1: 'c) (v2:'a b) = object method m1 () = v1 method b = v2 end;; class ['a, 'b] a : 'b -> 'a b -> object method b : 'a b method m1 : unit -> 'b end # f (new a 0 (new b 0));; - : int = 0 -- Yamagata Yoriyuki http://www.mars.sphere.ne.jp/yoriyuki/ ------------------- 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