From: Chris Quinn <cq@htec.demon.co.uk>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] checking for same ctor type?
Date: Fri, 29 Jun 2001 14:14:49 +0100 [thread overview]
Message-ID: <3B3C7F49.D058A72D@htec.demon.co.uk> (raw)
In-Reply-To: <200106280240.TAA14693@smtp2-cm.mail.eni.net>
Pervasives.compare is fine for nullary constructors or where you don't mind the performance hit of the function recursing into the structure of the arguments.
A more efficient equality predicate that is really just a cut down version of [compare]:
module Kludge =
struct
let cmp (a: 't) (b: 't) =
let a' = Obj.repr a and b' = Obj.repr b in
match Obj.is_block a', Obj.is_block b' with
| true,true ->
Obj.tag a' = Obj.tag b'
| false,false ->
a' = b'
| _ -> false
end
It of course relies on the physical representation of sum types.
It has the merit of working on a type of any number of constructors, but the mis-merit of also operating over functions for instance!
To constrain such a comparison to sum types would require it to be built into the compiler.
Chris Q.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
prev parent reply other threads:[~2001-06-29 13:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-28 2:40 Chris Hecker
2001-06-28 2:55 ` Brian Rogoff
[not found] ` <Pine.BSF.4.21.0106271950090.28760-100000@shell5.ba.best.co m>
2001-06-28 3:06 ` Chris Hecker
2001-06-29 13:14 ` Chris Quinn [this message]
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=3B3C7F49.D058A72D@htec.demon.co.uk \
--to=cq@htec.demon.co.uk \
--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