caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* RE: [Caml-list] a reckless proposal
@ 2001-07-25  9:30 Dave Berry
  2001-07-26 15:35 ` Miles Egan
  0 siblings, 1 reply; 14+ messages in thread
From: Dave Berry @ 2001-07-25  9:30 UTC (permalink / raw)
  To: Miles Egan, caml-list

> From: Miles Egan [mailto:miles@caddr.com]
> Sent: 24 July 2001 19:08
> 
> 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.  Objects seem
> to provide more struct-like semantics, i.e. field names need
> only be unique within their class definition.

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.

> 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, 

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.

-------------------
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


^ permalink raw reply	[flat|nested] 14+ messages in thread
* [Caml-list] a reckless proposal
@ 2001-07-24 18:08 Miles Egan
  2001-07-24 19:44 ` Brian Rogoff
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Miles Egan @ 2001-07-24 18:08 UTC (permalink / raw)
  To: caml-list

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.  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 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.

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.

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.

-- 
miles

"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


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2001-07-30 12:21 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-25  9:30 [Caml-list] a reckless proposal Dave Berry
2001-07-26 15:35 ` Miles Egan
2001-07-30 12:21   ` Bruce Hoult
  -- strict thread matches above, loose matches on Subject: below --
2001-07-24 18:08 Miles Egan
2001-07-24 19:44 ` Brian Rogoff
2001-07-24 21:02   ` Miles Egan
2001-07-25 15:15     ` Brian Rogoff
2001-07-26 15:27       ` Miles Egan
2001-07-26 15:47         ` Brian Rogoff
2001-07-26 16:01           ` Miles Egan
2001-07-26 21:19   ` John Max Skaller
2001-07-24 20:26 ` Sven
2001-07-24 20:51   ` Miles Egan
2001-07-25  8:30 ` FabienFleutot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).