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.4 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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 26A73BBC4 for ; Wed, 1 Apr 2009 01:16:09 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgQBACNB0klCbwQbc2dsb2JhbACWFAEMCgsHEQS3f4N6Bg X-IronPort-AV: E=Sophos;i="4.39,304,1235948400"; d="scan'208";a="25380859" Received: from out3.smtp.messagingengine.com ([66.111.4.27]) by mail3-smtp-sop.national.inria.fr with ESMTP; 01 Apr 2009 01:16:08 +0200 Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id 79220308D46; Tue, 31 Mar 2009 19:16:07 -0400 (EDT) Received: from heartbeat2.messagingengine.com ([10.202.2.161]) by compute1.internal (MEProxy); Tue, 31 Mar 2009 19:16:07 -0400 X-Sasl-enc: YrQmmmSFMBDlbEr1UQorRPdzX8TZuWfJ8h+FuP0sBWWd 1238541367 Received: from [192.168.1.10] (ALyon-157-1-87-173.w90-37.abo.wanadoo.fr [90.37.198.173]) by mail.messagingengine.com (Postfix) with ESMTPSA id CCD3954F46; Tue, 31 Mar 2009 19:16:06 -0400 (EDT) Message-ID: <49D2A372.3010800@ens-lyon.org> Date: Wed, 01 Apr 2009 01:12:50 +0200 From: Martin Jambon User-Agent: Thunderbird 2.0.0.17 (X11/20081008) MIME-Version: 1.0 To: Goswin von Brederlow Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Bug? Constraints get ignored in methods References: <87ab71ic1f.fsf@frosties.localdomain> <49D2A0AF.1080300@ens-lyon.org> In-Reply-To: <49D2A0AF.1080300@ens-lyon.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ens-lyon:01 bug:01 iter:01 iter:01 polymorphism:01 cheers:01 wrote:01 caml-list:01 jambon:01 jambon:01 constraints:03 inherits:03 let:03 let:03 derived:05 Martin Jambon wrote: > Use a classic list: > > > class base = ... > class derived = ... (* inherits base *) > > type obj = Base of base | Derived of derived > > let obj_list = [ Base (new base); Derived (new derived); ... ] > > let iter_base f l = > List.iter (function Base x -> f x | Derived x -> f (x :> base)) l > > let iter_derived f l = > List.iter (function Derived x -> f x | Base _ -> ()) l > > ... Or simply one list per type, each list containing all the elements compatible with the type. I would stay away from any solution that requires special methods in order to solve the polymorphism/heterogeneity problem. Keep the modifications non-invasive. Cheers, Martin -- http://mjambon.com/