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 VAA18757; Tue, 24 Jul 2001 21:44:55 +0200 (MET DST) 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 VAA18822 for ; Tue, 24 Jul 2001 21:44:55 +0200 (MET DST) Received: from shell5.ba.best.com (shell5.ba.best.com [206.184.139.136]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f6OJirb20025 for ; Tue, 24 Jul 2001 21:44:53 +0200 (MET DST) Received: from localhost (bpr@localhost) by shell5.ba.best.com (8.9.3/8.9.2/best.sh) with ESMTP id MAA01633 for ; Tue, 24 Jul 2001 12:44:52 -0700 (PDT) Date: Tue, 24 Jul 2001 12:44:52 -0700 (PDT) From: Brian Rogoff To: caml-list@inria.fr Subject: Re: [Caml-list] a reckless proposal In-Reply-To: <20010724110817.A35216@caddr.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, 24 Jul 2001, Miles Egan wrote: > It seems that two of the things that most confuse or frustrate new users of > ocaml are records and objects. Records are confusing because they resemble C > structs and are used in similar ways, but are really quite different. Objects > are confusing because their use is mildly discouraged and because their > functionality significantly overlaps that of the module system. > > The most frustrating feature of records, of course, is that each record field > name must be globally unique. Correction/amplification: not globally unique, but unique in a module. > Objects seem to provide more struct-like > semantics, i.e. field names need only be unique within their class definition. > Using objects in place of records is a bit clumsy, however, because object > fields require accessors. If the rules for object field access were changed, > however, objects would be just as convenient as records and less No, they'd still be *much* less convenient than records, since you can't pattern match on objects. Classes and types can't be in a recursive relationship either (though there are things you can do with row types here to ease this...). > confusing and more comfortable to C/C++/Java/Python programmers. For example, if object > fields were directly accessible by default, one could use: > > class point = > object > val x = 0 > val y = 0 > end > > and access p.x and p.y directly, which would be in almost all ways preferrable > to using a record type which would make it impossible to define another type > with fields named x or y. I do use classes instead of records sometimes, but you really do lose when you give up pattern matching! > Alternatively, ocaml could offer ruby-style accessor macros, where a definition > like: > > class example = > object > attr_rw x = 0 > attr_r y = 0 > attr z = 0 > end > > would automatically generate get_x and set_x methods for x, a get_y method for > y, and no methods for z. I suppose you could implement this in camlp4, but I > think features like this would have to be included in core ocaml before they'd > really be used. Records could even be deprecated if this were implemented. Deprecate records? No way! > This approach has, in my mind, two advantages: > 1. The object system becomes more generally useful. > 2. A confusing and non-orthogonal feature of ocaml is subsumed into > another, more generally useful and flexible feature. I understand this desire to unify features and remove non-orthogonalities, but I don't like this proposal. I think it would be more interesting to have a language with more polymorphism in records, as well as some more flexibility in modules. By enhancing those aspects of the language the advantages of classes would be reduced. Of course, if you're really into confusing, errr, unifying concepts, I suppose we could unify modules and records too? No joke, I think a few language designs do this. Anyways, I'd rather beef up records than try to eliminate them. The research language SML# had pretty expressive records. That may be a more promising direction. -- Brian ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr