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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 35D4DBB84 for ; Wed, 4 Jun 2008 16:24:17 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvUBAF5CRkjAXQIniGdsb2JhbACBVZAvAQEBDyCWd4cG X-IronPort-AV: E=Sophos;i="4.27,589,1204498800"; d="scan'208";a="11555489" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 04 Jun 2008 16:24:17 +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 m54EO61a024698 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 4 Jun 2008 16:24:16 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhIEAJxCRkhQDPIyZGdsb2JhbACBVZAiGgQDBAcQBpZ2hwY X-IronPort-AV: E=Sophos;i="4.27,589,1204498800"; d="scan'208";a="13489815" Received: from smtp23.orange.fr ([80.12.242.50]) by mail3-smtp-sop.national.inria.fr with ESMTP; 04 Jun 2008 16:24:16 +0200 Received: from smtp23.orange.fr (mwinf2304 [10.232.4.26]) by mwinf2305.orange.fr (SMTP Server) with ESMTP id 147081C2F9FF for ; Wed, 4 Jun 2008 15:33:07 +0200 (CEST) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2304.orange.fr (SMTP Server) with ESMTP id C4AEB1C0009B for ; Wed, 4 Jun 2008 15:33:05 +0200 (CEST) Received: from localhost.localdomain (Mix-Lyon-303-2-37.w193-248.abo.wanadoo.fr [193.248.44.37]) by mwinf2304.orange.fr (SMTP Server) with ESMTP id AA50C1C0009A for ; Wed, 4 Jun 2008 15:33:04 +0200 (CEST) X-ME-UUID: 20080604133304697.AA50C1C0009A@mwinf2304.orange.fr Date: Wed, 4 Jun 2008 13:40:35 +0200 From: Fabrice Marchant To: caml-list@inria.fr Subject: Problem with module inclusion Message-ID: <20080604134035.6f4ee0b1@orange.fr> X-Mailer: Claws Mail 3.2.0 (GTK+ 2.12.9; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 4846A586.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 functor:01 orderedtype:01 sig:01 sig:01 val:01 val:01 bool:01 bool:01 struct:01 printf:01 printf:01 functor:01 struct:01 orderedtype:01 Hi senior list ! Another question about learning OCaml : apologize. It lands here unchanged from Beginners list : Here is a counter functor : *) module Counters ( X : Map.OrderedType ) : sig module XMap : sig type 'a t = 'a Map.Make(X).t val empty : 'a t val add : X.t -> 'a -> 'a t -> 'a t val find : X.t -> 'a t -> 'a val fold : (X.t -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool end type t = int XMap.t val equal : t -> t -> bool val zeroes : t val incr : t -> X.t -> t val to_list : t -> (X.t * int) list end = struct module XMap = Map.Make( X ) type t = int XMap.t let equal = XMap.equal ( = ) let zeroes = XMap.empty let incr map e = (XMap.add e (try succ (XMap.find e map) with Not_found -> 1)) map let to_list map = XMap.fold (fun k d a -> (k, d) :: a ) map [] end module StringCounters = Counters ( String ) let _ = let l= ["7"; "8192"; "7"; "199"; "199"; "7"; "7"] in Printf.printf "[\"%s\"] -> %s\n" (String.concat "\"; \"" l) (String.concat " + " (List.map (fun (k, d) -> (string_of_int d) ^ "x\"" ^ k ^ "\"") (StringCounters.to_list (List.fold_left StringCounters.incr StringCounters.zeroes l)))) (* -> 1x"8192" + 4x"7" + 2x"199" *) (* My problem is I want to reject the 'to_list' function (that isn't specific to counting) from Counters functor to an extension of Map : So I tried to define : *) module MapPlus ( Map : Map.S ) = struct include Map let to_list map = Map.fold (fun k d a -> (k, d) :: a ) map [] end (* before Counters, that would be modified this way : *) module Counters ( X : Map.OrderedType ) : sig module XMap : sig type 'a t = 'a Map.Make(X).t val empty : 'a t val add : X.t -> 'a -> 'a t -> 'a t val find : X.t -> 'a t -> 'a val fold : (X.t -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool end type t = int XMap.t val equal : t -> t -> bool val zeroes : t val incr : t -> X.t -> t end = struct module XMap = MapPlus ( Map.Make( X ) ) type t = int XMap.t let equal = XMap.equal ( = ) let zeroes = XMap.empty let incr map e = (XMap.add e (try succ (XMap.find e map) with Not_found -> 1)) map end (* unfortunately this doesn't work : how to access 'to_list' function through the Counters module ? With StringCounters.XMap.to_list ? I'm confused. Should the Counters signature be modified ? Fabrice