From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] type of ==
Date: Mon, 18 Apr 2005 15:28:29 +0100 [thread overview]
Message-ID: <200504181528.29618.jon@ffconsultancy.com> (raw)
In-Reply-To: <001901c5440f$ce1a5e80$14b2a8c0@wiko>
On Monday 18 April 2005 13:11, Andreas Rossberg wrote:
> Either when 'a and 'b happen to be instantiated to the same type,
Yes, I realised this just after posting (thanks Diego!).
> or when the representation happens to be the same, e.g. 0 == false.
Assuming this is for an OCaml-only program, it sounds as though the "other"
possible types 'a and 'b should be put into a single variant type. Then you
can use "'a -> 'a -> bool" with "'a = your variant type". Does that make any
sense? :-)
You'd have to indirect the physical equality once though, e.g.:
# type ('a, 'b) a = A of 'a | B of 'b;;
type ('a, 'b) a = A of 'a | B of 'b
# let compare_a x y = match x, y with
A x, A y -> x == y
| B x, B y -> x == y
| _ -> false;;
val compare_a : ('a, 'b) a -> ('a, 'b) a -> bool = <fun>
A good excuse not to do this would be when you're writing a veneer between
OCaml and C in OCaml.
> The latter also provides a good argument against making physical equality
> too polymorphic. It would break abstraction, much worse than it does
> already. In particular, a program's meaning could depend on implementation
> details (like false being represented by 0) in very questionable ways.
Yes, although this is already the case when applying "=" to abstract types
(implementation of the type in that case, rather than of the language
itself).
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists
next prev parent reply other threads:[~2005-04-18 19:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-18 9:18 Christophe DEHLINGER
2005-04-18 11:27 ` [Caml-list] " Jon Harrop
2005-04-18 12:11 ` Andreas Rossberg
2005-04-18 13:10 ` Christophe DEHLINGER
2005-04-18 14:28 ` Jon Harrop [this message]
2005-04-19 7:12 ` [Caml-list] type of == - Bayesian Filter detected spam Christophe DEHLINGER
2005-04-18 16:16 ` [Caml-list] type of == Remi Vanicat
2008-01-05 16:41 Type_of? Dario Teixeira
2008-01-05 17:12 ` [Caml-list] Type_of? Jeremy Yallop
2008-01-05 17:43 ` Arnaud Spiwack
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=200504181528.29618.jon@ffconsultancy.com \
--to=jon@ffconsultancy.com \
--cc=caml-list@yquem.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