caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: diego-olivier.fernandez-pons@cicrp.jussieu.fr
Cc: caml-list@inria.fr, rossberg@ps.uni-sb.de
Subject: Re: [Caml-list] Improper generic equality in Caml (Rossberg's SML vs Caml)
Date: Sun, 17 Sep 2006 05:58:21 +0900 (JST)	[thread overview]
Message-ID: <20060917.055821.94069241.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <Pine.A41.4.44.0609162018590.1511520-100000@ibm1>

From: Diego Olivier Fernandez Pons <Diego.FERNANDEZ_PONS@etu.upmc.fr>

> What does Andreas Rossberg in his SML vs. Caml page
> 
>     http://www.ps.uni-sb.de/~rossberg/SMLvsOcaml.html
> 
> mean when he says that
> 
>    [Caml] Does not have a proper generic equality
>    on one hand (1, r) != (1, r), on the other (1, r) = (1, ref 1)

The word "proper" is a bit strange (SML-centric), but the meaning is
indeed that in ocaml you need two kinds of equalities, while in SML
you can do with one.
You have a taste of the SML way with objects:

# class c =
  object val mutable x = 0 method set x' = x <- x' method get = x end;;
class c :
  object val mutable x : int method get : int method set : int -> unit end
# new c = new c;;
- : bool = false

Namely, in SML only immutable values are compared structurally,
mutable ones being compared by pointer.
The main advantage is that there is no need for physical equality,
knowing that physical equality sometimes allows to distinguish between
things that should be identical. This is completed by the use of
so-called equality types, so that you cannot use equality on abstract
types, where it may break abstraction.

I personally like the idea of automatically using pointer equality on
mutables. However pointer equality sometimes comes as a handy
optimization for immutable values too, so going a long way to exclude
it from the language may seem a bit harsh.

By the way, I don't think that his statement is connected with the
incoherence between structural and physical equality on Nan, which is
a rather recent phenomenon in ocaml.

Jacques Garrigue


  reply	other threads:[~2006-09-16 20:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-09  3:11 Comparing two things of any two types, in pure OCaml oleg
2006-09-09  7:13 ` [Caml-list] " Jacques Garrigue
2006-09-13  9:14   ` [Caml-list] Comparing two things of any two types, in pure oleg
2006-09-16 18:53     ` Improper generic equality in Caml (Rossberg's SML vs Caml) Diego Olivier Fernandez Pons
2006-09-16 20:58       ` Jacques Garrigue [this message]
2006-09-17  5:08       ` [Caml-list] " rossberg
2006-09-17  9:45         ` skaller
2006-09-17 12:43           ` rossberg
2006-09-14  4:36   ` [Caml-list] Comparing two things of any two types, in pure OCaml brogoff

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=20060917.055821.94069241.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=diego-olivier.fernandez-pons@cicrp.jussieu.fr \
    --cc=rossberg@ps.uni-sb.de \
    /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;
as well as URLs for NNTP newsgroup(s).