From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Type abstraction and (polymorphic) equality
Date: Wed, 29 Jun 2005 10:12:30 +0100 [thread overview]
Message-ID: <200506291012.30612.jon@ffconsultancy.com> (raw)
In-Reply-To: <20050629.023111.15476874.debian00@tiscali.be>
On Wednesday 29 June 2005 01:31, Christophe TROESTLER wrote:
> One may argue that its my fault: I should have declared from the start
> a function
>
> val eq : t -> t -> bool
Yes, if you're doing anything which you think may be extended later then I
think it is a good idea to try to discipline yourself in this way (don't use
built-in polymorphic equality).
> * Is there a solution in the current state of OCaml? (I'll be glad if
> there is.)
I do not believe so. IIRC, SML has equality types to help with this problem.
> * If the first answer is "no", is there a medium term perspective to
> bring a solution to this problem? I can see two:
>
> - one allows to redefine equality for new types, say with a syntax
> like
>
> type t = ... with compare x y = ...
>
> as this is already done for blocks with custom tags. (BTW, why
> aren't Big_int such blocks with an appropriate compare?)
That looks lovely. Apparently a similar facility is available in Haskell.
However, there are disadvantages. Unless you're doing whole-program
compilation, you'll need to carry a compare function with every datum. That's
a huge performance cost and it probably isn't too easy to optimise it away.
> - One introduces the same capability of providing a special equality
> (comparison) for certain types but, during compilation, "expand"
> functions till the type for "=" is given by known functions
> (something like a "generic" equality). I guess however that that
> may cause problems with separate compilation...
Yes. It seems that this kind of thing is best done by a MLton-like compiler.
If this is a trade-off then I prefer OCaml's current position - MLton is an
order of magnitude slower to compile small programs, no dynamic code loading,
no marshalling etc.
> I'll be glad to hear similar experiences and comments about the above
> ideas.
I had a similar problem when I extended an AST type to include lazily
evaluated information. I suddenly got comparisons raising "function type"
exceptions everywhere. The best solution recommended to me was to temporarily
replace "=" with my own monomorphic version. That's hardly elegant and only
works well if you've only used "=" on the one type that you're interested in.
I was convinced that there must be a simpler solution to this problem, using a
static checker. However, the more I looked into my seemingly great idea, the
harder it got... :-)
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Technical Presentation Software
http://www.ffconsultancy.com/products/presenta
next prev parent reply other threads:[~2005-06-29 9:14 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-29 0:31 Christophe TROESTLER
2005-06-29 9:12 ` Jon Harrop [this message]
2005-06-29 10:06 ` [Caml-list] " Andreas Rossberg
2005-06-29 13:32 ` Christophe TROESTLER
2005-06-29 23:39 ` brogoff
2005-06-30 7:46 ` Christophe Raffalli
2005-06-29 20:27 ` Christophe TROESTLER
2005-06-29 20:37 ` John Skaller
2005-06-30 9:53 ` Andreas Rossberg
2005-06-30 17:08 ` brogoff
2005-06-30 17:22 ` Andreas Rossberg
2005-06-30 19:56 ` John Skaller
2005-07-01 12:49 ` Andreas Rossberg
2005-06-29 9:45 ` Jean-Christophe Filliatre
2005-06-29 17:33 ` William Lovas
2005-06-29 18:08 ` sejourne_kevin
2005-06-30 9:51 ` Andreas Rossberg
2005-06-30 19:54 ` John Skaller
2005-06-30 22:24 ` Alain Frisch
2005-06-30 12:19 ` Alain Frisch
2005-06-30 12:32 ` padiolea
2005-06-30 12:57 ` Alain Frisch
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=200506291012.30612.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