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.3 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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 7CD00BBC4 for ; Wed, 1 Apr 2009 13:45:19 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoIAACTw0klCbwQbk2dsb2JhbACWFgEBAQEJCQoJEQS4EoN6Bg X-IronPort-AV: E=Sophos;i="4.39,306,1235948400"; d="scan'208";a="37644365" Received: from out3.smtp.messagingengine.com ([66.111.4.27]) by mail4-smtp-sop.national.inria.fr with ESMTP; 01 Apr 2009 13:45:19 +0200 Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id D475330DA8A; Wed, 1 Apr 2009 07:45:17 -0400 (EDT) Received: from heartbeat2.messagingengine.com ([10.202.2.161]) by compute1.internal (MEProxy); Wed, 01 Apr 2009 07:45:17 -0400 X-Sasl-enc: T89XjxEfsYSaisWCowxwZdpZeK9g1AR6JRGZ+Pl3xoR0 1238586317 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 32BC055228; Wed, 1 Apr 2009 07:45:17 -0400 (EDT) Message-ID: <49D35307.4000502@ens-lyon.org> Date: Wed, 01 Apr 2009 13:41:59 +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> <87prfx6xsc.fsf@frosties.localdomain> In-Reply-To: <87prfx6xsc.fsf@frosties.localdomain> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ens-lyon:01 bug:01 prev:01 functors:01 mutable:01 val:01 val:01 wrote:01 caml-list:01 constraint:01 int:01 jambon:01 jambon:01 data:02 data:02 Goswin von Brederlow wrote: > Hi, > > small add on to my last mail. > > Think of it as having a set of work queues: clean, dirty, reading, > writing, write_prepare. The objects need to be able to quickly jump > from one queue to the back of another when the objects internal state > changes. And is not only the objects at the head of the queue that > change states. Can be pretty random what object changes. > > If I put the prev/next links into the objects themself they can easily > detach themself from a queue and insert themself into another. > > If I put the objects into other generic queue structures then I have to > find the position in the old queue to remove an object and that would > be slow. > > > If you can think of a solution that would allow > > type 'a data = { next : 'b data option; data : 'a } > > without having to know possibly types of 'b then I could use functors. > > This would have to work: > > let s = { next = None; data = "string" } > let i = { next = Some s; data = 23 } Would the following work for you: type 'a linked = { data : 'a; mutable next : < > linked option } (* constraint 'a = < .. > *) let create data next = { data = data; next = (next :> < > linked option) } let set_next x y = x.next <- (y :> < > linked option) class s = object method s = "abc" end class i = object method i = 123 end let s = create (new s) None let i = create (new i) (Some s) val create : 'a -> < .. > linked option -> 'a linked = val set_next : 'a linked -> < .. > linked option -> unit = class s : object method s : string end class i : object method i : int end val s : s linked = {data = ; next = None} val i : i linked = {data = ; next = Some {data = ; next = None}} -- http://mjambon.com/