From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p4NBH7bU024260 for ; Mon, 23 May 2011 13:17:07 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgYRAI5B2k1iiluDaGdsb2JhbACXdTGOEA0JDQURAyikMY5dgjWDZIkZAQQFAYYTBIZQjXAmikA X-IronPort-AV: E=Sophos;i="4.65,256,1304287200"; d="scan'208";a="83727680" Received: from nm1-vm3.bullet.mail.ne1.yahoo.com ([98.138.91.131]) by mail3-smtp-sop.national.inria.fr with SMTP; 23 May 2011 13:17:01 +0200 Received: from [98.138.90.50] by nm1.bullet.mail.ne1.yahoo.com with NNFMP; 23 May 2011 11:17:00 -0000 Received: from [98.138.89.171] by tm3.bullet.mail.ne1.yahoo.com with NNFMP; 23 May 2011 11:17:00 -0000 Received: from [127.0.0.1] by omp1027.mail.ne1.yahoo.com with NNFMP; 23 May 2011 11:17:00 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 303142.87008.bm@omp1027.mail.ne1.yahoo.com Received: (qmail 53699 invoked by uid 60001); 23 May 2011 11:17:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1306149420; bh=D3ChQ7N2V0dfgshcrmNov1eNQM+fwHGPpxXpgNbe+7k=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=XzuCX3o6IRxDqoHYgmwRiTZIZKpZSHozgoV7VZ/NTjy4/6pOPwjccbKCsCH7XAJN/NPzmP2fsT7WJzV+yNtumTOVaFxO2RwTnLrgWN0HIlnkbhDw4liriDoHPUG/cPPK67podpw4CSamguS5YdNBGZ+ZVwvNPdBDdvjIjBK4/7s= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=2N8AI2Ixn4yPKcf5mYm8TDKxYkriih5jnGGhUufqUAZnivfhaRdrJgrBbigBkIyt0/L8I8Zb5AJjbQ1TVr2gY+VvifEGMwFQHxv+WpHk8pnXTXsFHMAio7rZhPu+S3Qo+wMZDRDBYLqH13Ow2t8jJI3O7AmP4tIr92Lggmp9Wag=; Message-ID: <172756.45853.qm@web120203.mail.ne1.yahoo.com> X-YMail-OSG: Vs2Yhr8VM1ko4Jf2uwjPq9MZ.TYlhkYRT4ct4IxSL9l6zVB bvltQf6T2TCVGGCAl7Vj675ls7Ujf7CnGlJC4T29uEMlzthZzXOVo0t.xvXI f73scRZBRl02WZ18gJhdBLkUebEZWOJ9FyTvid.PPa1cYSUqYiBFFlQY2VKm 9ohRcFUz4or1K9GJ7t9pxI5yzV8WLef4xuC9gLgYNHvRbPosQu7URrYQ9axu 9exeS_zEtez.JNBx3H9Ou0G7hGks_nxgl.1dAEgEwSuJXk6Myv2t5Jbe4FnO dGm4x8qXHrGB1BoF8QQiTvdvA4OnH29GWZZ_9lHJS1Rh142pEA124DXp.H_P a.VScFWhdpECwv9D5kaHTq_2qmMVEcTwF.rNjpAbTy8Yr6JQnFi6sjBw- Received: from [70.35.43.162] by web120203.mail.ne1.yahoo.com via HTTP; Mon, 23 May 2011 04:17:00 PDT X-Mailer: YahooMailRC/567 YahooMailWebService/0.8.111.303096 Date: Mon, 23 May 2011 04:17:00 -0700 (PDT) From: Hakan Suka To: caml-list@inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: [Caml-list] functor inside a class Hi everyone, I tried the ocaml-beginners list with this question but did not get a good solution, so I am retrying here. I want to create a parameterised class that takes as input a polymorphic "label" type and internally stores information using a Set of that type. However, I cannot get the functor to work inside a class, so I wonder whether this is possible. For example, the following works: module LabelSet = Set.Make (struct type t = int let compare = compare end) class ['a] tracker size = object val nums_to_track_tbl : (int32, LabelSet.t) Hashtbl.t = Hashtbl.create size method get pos = Hashtbl.find_all nums_to_track_tbl pos end But can I have a local module definition so that the I can have a tracker not only for integers, but for any type being passed as input? The following does not work: class ['a] tracker size = let module LabelSet = Set.Make (struct type t = 'a let compare = compare end) in object val nums_to_track_tbl : (int32, LabelSet.t) Hashtbl.t = Hashtbl.create size method get pos = Hashtbl.find_all nums_to_track_tbl pos end If this is not possible, would it work in Ocaml 3.12 with first-class modules? I have seen the following code in the manual which seems fairly close of what I would need inside the parametrised class, but not sure if I can use the output of make_set inside the module. I haven't tested this because I have Ocaml 3.11.2 let make_set (type s) cmp = let module S = Set.Make(struct type t = s let compare = cmp end) in (module S : Set.S with type elt = s) If that does not work, any suggestions on how to implement this? Thanks, Hakan