From: Jacques GARRIGUE <garrigue@kurims.kyoto-u.ac.jp>
To: fessant@pa.dec.com
Cc: caml-list@inria.fr
Subject: Re: Objects contrib: new URL ...
Date: Fri, 18 Jun 1999 10:19:02 +0900 [thread overview]
Message-ID: <19990618101902C.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: Your message of "Thu, 17 Jun 1999 10:16:32 -0700 (PDT)" <14185.11632.214915.820706@virtualc5.pa.dec.com>
From: Fabrice Le Fessant <fessant@pa.dec.com>
> In our case, the "cast" construct for the object-oriented programing
> style can be compared to the "ref" or the "array" types for the
> imperative programming style. Both can lead to "unsafe" programs
> (should the compiler allow "x.(-1)" in a program as it currently does?),
> but they can still be useful when used carefully. In that way, I trust
> Ocaml users (demagogy :)).
Agreed for array indices. Looks like a "needed evil" since the only
way to avoid it would be dependent types (still, some people work at
it).
I don't see what is the problem with refs? This is an impure
feature, but not dangerous in terms of type safety.
And of course there are also exceptions, which are pretty bad when
used the wrong way.
> With this patch, I tried to increase the expressiveness of the language,
> without breaking its safety. In this way, I think it is still better
> than using Obj.magic, since the "implements" checks whether the types
> can correctly be coerced.
I agree that this is better than Obj.magic. However it lets people
program in a JAVA-like style, quitting safe parametric polymorphism
(i.e. parametric classes) for unsafe dynamic type checking.
With your patch one can define collection classes without parameter,
put anything inside them, and downcast to get the contents, like one
does in JAVA.
The problem is that lots of people come to caml from a world where
casts are the standard way to obtain polymorphism. If you provide it
with an easy syntax, they will not bother to learn about the benefits
of parametric polymorphism (anti-demagogy :)).
So I weaken my statement: casts are not an absolute evil which should
not be allowed at all, but at least they should be hard to use, enough
to encourage people to choose other methods when possible.
> > Remark:
> > You can already implement something similar inside the language:
>
> Can you really use an object (mutable) as the key in the hashtbl (its
> hash value may change when it is modified ?) ?
Objects have a unique oid, which is used for comparisons and hashing.
Cf. byterun/hash.c.
I must admit that your approach is more efficient, since you just have
to check the pointer to the class. But again perfection may be a bad
thing for an unsafe feature...
Regards,
Jacques
P.S. Thanks for your path-to-the-patch.
next prev parent reply other threads:[~1999-06-18 15:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-06-15 21:45 Objects contrib Fabrice Le Fessant
1999-06-16 8:13 ` Vyskocil Vladimir
1999-06-16 15:56 ` Objects contrib: new URL Fabrice Le Fessant
1999-06-17 2:26 ` Jacques GARRIGUE
1999-06-17 17:16 ` Fabrice Le Fessant
1999-06-17 18:44 ` Stefan Monnier
1999-06-18 1:19 ` Jacques GARRIGUE [this message]
1999-06-21 11:41 Don Syme
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=19990618101902C.garrigue@kurims.kyoto-u.ac.jp \
--to=garrigue@kurims.kyoto-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=fessant@pa.dec.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox