From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 2E22EBBAF for ; Thu, 29 May 2008 10:14:34 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlQBAGsCPkjAXQIniGdsb2JhbACSKAEBAQ8gnQo X-IronPort-AV: E=Sophos;i="4.27,560,1204498800"; d="asc'?scan'208";a="12886135" Received: from concorde.inria.fr ([192.93.2.39]) by mail1-smtp-roc.national.inria.fr with ESMTP; 29 May 2008 10:14:33 +0200 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m4T8EX1s012377 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 29 May 2008 10:14:33 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AowAAOMCPkjBMHhLomdsb2JhbACSKAEBAQEBCAUGCRGdCQ X-IronPort-AV: E=Sophos;i="4.27,560,1204498800"; d="asc'?scan'208";a="13193470" Received: from net.univ-savoie.fr ([193.48.120.75]) by mail3-smtp-sop.national.inria.fr with ESMTP; 29 May 2008 10:14:32 +0200 Received: from post.bourget.univ-savoie.fr (post.bourget.univ-savoie.fr [193.48.120.73]) by net.univ-savoie.fr (8.12.3/jtpda-5.4) with ESMTP id m4T8E681002274 ; Thu, 29 May 2008 10:14:12 +0200 Received: from d45.lama.univ-savoie.fr (d45.lama.univ-savoie.fr [193.48.123.45]) by post.bourget.univ-savoie.fr (8.12.3/jtpda-5.4) with ESMTP id m4T8DLu0014460 ; Thu, 29 May 2008 10:13:22 +0200 Message-ID: <483E65A0.3060405@univ-savoie.fr> Date: Thu, 29 May 2008 10:13:20 +0200 From: Christophe Raffalli User-Agent: Thunderbird 2.0.0.12 (X11/20080227) MIME-Version: 1.0 To: Jon Harrop Cc: peng.zang@gmail.com, caml-list Subject: Re: [Caml-list] on objects, equality and playing nicely with the stdlib References: <200805290050.36980.peng.zang@gmail.com> <200805290813.18027.jon@ffconsultancy.com> In-Reply-To: <200805290813.18027.jon@ffconsultancy.com> X-Enigmail-Version: 0.95.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig7B277DF8B25CA39A4C4A4C1D" X-Scanned-By: MIMEDefang 2.33 (www . roaringpenguin . com / mimedefang) X-Miltered: at concorde with ID 483E65E9.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; christophe:01 raffalli:01 christophe:01 raffalli:01 univ-savoie:01 stdlib:01 subtyping:01 stdlib:01 hashtbl:01 hashtbl:01 functor:01 hash:01 hashing:01 functor:01 syntax:01 X-Attachments: type="application/pgp-signature" name="signature.asc" name="signature.asc" This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig7B277DF8B25CA39A4C4A4C1D Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Jon Harrop a =E9crit : > 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'v= e >> 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 (=3D) operator performs. Namely, it makes several st= dlib >> modules difficult to use. Modules that provides a polymorphic (generi= c) >> interface such as Hashtbl, List, Stack, etc.. rely on the (=3D) operat= or.=20 >> 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 yo= u >> have your own equality function? This problem almost never shows up i= f you >> just stick with basic data types, but with objects you quickly run int= o it. >=20 > Hi Peng, >=20 > You can use the Hashtbl.Make functor to create hash tables using your o= wn=20 > equality (and hashing) function. Other than that, you're screwed: resor= t to=20 > cut and paste from the stdlib. >=20 Via Custom block (section 18.9.1 of the manual), you could create a funct= or with the following shape (I did not check my syntax): module type Quotient =3D type t type qt val class : t -> qt val get_representent : qt -> t end module type Equivalence =3D type t val compare : t -> t -> int end module Make_Quotient (R : Equivalence) : Quotient with type t =3D R.t Such that (class x) builds a custom block with the given compare as comparison function ... You can add hash and serialization to the Equivalence type too ... It is a pity we have to do that from C, this should be the default way to bridge the gap between polymorphic comparison and specific comparison.= (and PML will provide a buildin class constructor in the near future). Hope this helps, Christophe --=20 Christophe Raffalli Universite de Savoie Batiment Le Chablais, bureau 21 73376 Le Bourget-du-Lac Cedex tel: (33) 4 79 75 81 03 fax: (33) 4 79 75 87 42 mail: Christophe.Raffalli@univ-savoie.fr www: http://www.lama.univ-savoie.fr/~RAFFALLI --------------------------------------------- IMPORTANT: this mail is signed using PGP/MIME At least Enigmail/Mozilla, mutt or evolution can check this signature. The public key is stored on www.keyserver.net --------------------------------------------- --------------enig7B277DF8B25CA39A4C4A4C1D Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFIPmWli9jr/RgYAS4RAiwZAJ9rCo/s367yJpVVkhoO8vNT7Tp+rACfcMCR 3rhIPI40+bM0UK/7R5HEAUU= =QvCx -----END PGP SIGNATURE----- --------------enig7B277DF8B25CA39A4C4A4C1D--