Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* polymorphic equality and overloading
@ 2000-06-29 21:10 Eijiro Sumii
  2000-06-30 17:08 ` Brian Rogoff
  0 siblings, 1 reply; 13+ messages in thread
From: Eijiro Sumii @ 2000-06-29 21:10 UTC (permalink / raw)
  To: caml-list; +Cc: sumii

Dear Caml Developers/Users,

(sorry that I don't know French)

This might be an FAQ, but could someone please give a rationale to the
polymorphic (in)equalities such as = and < in Caml?  While they have a
parametric polymorphic type 'a -> 'a -> bool, their semantics is ad
hoc rather than parametric with respect to the type 'a (for example,
they are undefined for functions), which I found confusing to some
users---at least, a friend of mine was confused, and chose Haskell
(which has type classes) over Caml!

// Eijiro Sumii <sumii@saul.cis.upenn.edu>
//
// currently visiting: Department of Computer and Information Science,
// School of Engineering and Applied Science, University of Pennsylvania



^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: polymorphic equality and overloading
@ 2000-07-05 22:40 John R Harrison
  0 siblings, 0 replies; 13+ messages in thread
From: John R Harrison @ 2000-07-05 22:40 UTC (permalink / raw)
  To: caml-list; +Cc: John Harrison


Eijiro Sumii writes:

| But as you know (and as I wrote in my previous messages), the
| polymorphic equality in Caml is not at all the "equality in
| mathematics" for many (or most?) datatypes.

Probably "most" is an exaggeration. But there are quite a few examples.
One I haven't seen mentioned in this thread is the type of floating point
numbers. The equality relation defined in the main standard for binary
floating point arithmetic (IEEE 754) is not reflexive. Specifically x = x
is false if x is a NaN ("not a number"). So again, this is really an
instance of overloading in CAML:

  #let x = 0.0 /. 0.0;;
  x : float = nan.0
  #x = x;;
  - : bool = false
  #x == x;;
  - : bool = true

Nevertheless, I find the CAML polymorphic equality and orderings pretty
useful and superficially simple, even if they sometimes have a touch of
arbitrariness about them.

Is it possible using just equality, not orderings, to write a set-compare
operation on polymorphic lists using fewer than 0(n^2) operations?
Trivially, using orderings, one can just sort both lists in O(n log n)
operations then run along them in order. Is there something comparably
efficient just using equality?

John.



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

end of thread, other threads:[~2000-07-07 14:35 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-29 21:10 polymorphic equality and overloading Eijiro Sumii
2000-06-30 17:08 ` Brian Rogoff
2000-06-30 17:51   ` Eijiro Sumii
2000-07-04  7:09     ` Jacques Garrigue
2000-07-04 12:42       ` Eijiro Sumii
2000-07-05  1:11         ` Jacques Garrigue
2000-07-05  2:37           ` Eijiro Sumii
2000-07-05 21:22         ` Pierre Weis
2000-07-05 21:30           ` Eijiro Sumii
2000-07-05 22:15             ` Pierre Weis
2000-07-05 23:09               ` Eijiro Sumii
2000-07-06 17:18             ` Benjamin Werner
2000-07-05 22:40 John R Harrison

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox