English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
RE: [Caml-list] a reckless proposal
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-07-26 (15:35)
From: Miles Egan <miles@c...>
Subject: Re: [Caml-list] a reckless proposal
On Wed, Jul 25, 2001 at 10:30:09AM +0100, Dave Berry wrote:
> So perhaps Ocaml should adopt the approach used in Dylan and Moby,
> where field names in class definitions have module scope.  Then
> records and objects would have similar scoping rules, instead of
> the current clash, and the distinction between modules and objects
> would be clearer.

I suppose this is also similar to CLOS generics, right?  I suppose this would be
more consistent but perhaps even more confusing to people who've been writing
ClassA.field and ClassB.field since the first day of their first Java class.

> But if you then replace the field with an accessor method, you
> have to edit all uses of that field.  It's a common recommendation
> that OO languages should only access field by accessor methods (or
> at least use the same syntax as accessor methods).  As you point
> out, Ruby does it this way.  Dylan and Eiffel are other examples.

Ocaml could observe this protocol as well.  This is valid code:

class a =
    val x = 1
    method x = x

let _ = new a in

So a "macro" like attr_r could transform:

class a =
   attr_r x = 1

into the above class definition.

Of course, you won't be able to assign to x in the way you'd expect:

let _ = new a in
  a#x = 2

Won't work.


"We in the past evade X, where X is something which we believe to be a
lion, through the act of running." - swiftrain@geocities.com
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