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 EEDF7BBAF for ; Thu, 29 May 2008 09:18:15 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhICAIf1PUjAXQIniGdsb2JhbACCM491AQEBDyCdDg X-IronPort-AV: E=Sophos;i="4.27,560,1204498800"; d="scan'208";a="12882285" Received: from concorde.inria.fr ([192.93.2.39]) by mail1-smtp-roc.national.inria.fr with ESMTP; 29 May 2008 09:18:15 +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 m4T7IDci009795 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 29 May 2008 09:18:15 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoQCAP/1PUjUnw7XcGdsb2JhbACCM491AQwFAgQHE50S X-IronPort-AV: E=Sophos;i="4.27,560,1204498800"; d="scan'208";a="13189940" Received: from fhw-relay07.plus.net ([212.159.14.215]) by mail3-smtp-sop.national.inria.fr with ESMTP; 29 May 2008 09:18:14 +0200 Received: from [80.229.56.224] (helo=beast.local) by fhw-relay07.plus.net with esmtp (Exim) id 1K1cOr-0002d9-H9; Thu, 29 May 2008 08:18:13 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: peng.zang@gmail.com, "caml-list" Subject: Re: [Caml-list] on objects, equality and playing nicely with the stdlib Date: Thu, 29 May 2008 08:13:15 +0100 User-Agent: KMail/1.9.9 References: <200805290050.36980.peng.zang@gmail.com> In-Reply-To: <200805290050.36980.peng.zang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200805290813.18027.jon@ffconsultancy.com> X-Plusnet-Relay: 4b3ba8a125b48ae135c892f1a790df9f X-Miltered: at concorde with ID 483E58B5.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; stdlib:01 subtyping:01 stdlib:01 hashtbl:01 hashtbl:01 functor:01 hash:01 hashing:01 peng:98 peng:98 frog:98 equality:01 equality:01 polymorphic:01 wrote:01 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