caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jon Harrop <jon@ffconsultancy.com>
To: peng.zang@gmail.com, "caml-list" <caml-list@inria.fr>
Subject: Re: [Caml-list] on objects, equality and playing nicely with the stdlib
Date: Thu, 29 May 2008 08:13:15 +0100	[thread overview]
Message-ID: <200805290813.18027.jon@ffconsultancy.com> (raw)
In-Reply-To: <200805290050.36980.peng.zang@gmail.com>

On Thursday 29 May 2008 05:50:33 Peng Zang wrote:
> Hello list,
>
> Recently, in building some toy games, I've started using objects.  I've
> been pleased with them and often find the subtyping convenient.
>
> However, I've run into some issues with the standard physical equality of
> objects that the (=) operator performs.  Namely, it makes several stdlib
> modules difficult to use.  Modules that provides a polymorphic (generic)
> interface such as Hashtbl, List, Stack, etc.. rely on the (=) operator. 
> This is fine as long as it happens to be what I need.  The minute I
> introduce my own equality however, things break down.
>
> What is the best way to go about using the stdlib (or similar) when you
> have your own equality function?  This problem almost never shows up if you
> just stick with basic data types, but with objects you quickly run into it.

Hi Peng,

You can use the Hashtbl.Make functor to create hash tables using your own 
equality (and hashing) function. Other than that, you're screwed: resort to 
cut and paste from the stdlib.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e


  reply	other threads:[~2008-05-29  7:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-29  4:50 Peng Zang
2008-05-29  7:13 ` Jon Harrop [this message]
2008-05-29  8:13   ` [Caml-list] " Christophe Raffalli
2008-05-29 13:25     ` Peng Zang

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=200805290813.18027.jon@ffconsultancy.com \
    --to=jon@ffconsultancy.com \
    --cc=caml-list@inria.fr \
    --cc=peng.zang@gmail.com \
    /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).