caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: rossberg@ps.uni-sb.de
To: caml-list@inria.fr
Subject: Re: [Caml-list] Improper generic equality in Caml (Rossberg's SML  vs Caml)
Date: Sun, 17 Sep 2006 07:08:20 +0200 (CEST)	[thread overview]
Message-ID: <1667.72.254.55.251.1158469700.squirrel@www.ps.uni-sb.de> (raw)
In-Reply-To: <Pine.A41.4.44.0609162018590.1511520-100000@ibm1>

Diego Olivier Fernandez-Pons wrote:
>
> 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)

To clarify: "proper" refers to "generic".

The problem example is the one given on the left-hand side of the table.
Let me elaborate.

OCaml has two equalities: one fully structural, the other physical. Both
work fine in special cases, but neither has the "right" semantics in the
general case, where you deal with an arbitrary mixture of structural and
mutable types. By "right" I mean equality in the standard Leibniz sense,
where you can always replace equals with equals, without changing the
outcome. Neither of OCaml's operators has this property.

More conretely, given

  let r = ref 1

then the pairs (1, r) and (1, ref 1) are distinguishable by the effect of
assignment. Still, OCaml's = considers them equal. On the other hand, it
is not observable (by other means) whether the pair (1, r) is constructed
once or twice, but == distinguishes these cases. Consequently, neither
operator implements equality "correctly" on type (int * int ref), because
either delivers a "wrong" result for one of these two examples.

This problem can sometimes make translation from SML (which has Leibniz
equality) to OCaml subtly difficult (that the inverse direction is
potentially difficult is more obvious).

Cheers,
- Andreas



  parent reply	other threads:[~2006-09-17  5:08 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       ` [Caml-list] " Jacques Garrigue
2006-09-17  5:08       ` rossberg [this message]
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=1667.72.254.55.251.1158469700.squirrel@www.ps.uni-sb.de \
    --to=rossberg@ps.uni-sb.de \
    --cc=caml-list@inria.fr \
    /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).