From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 5F9F9BC57 for ; Mon, 20 Sep 2010 21:36:04 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApgAAAZVl0xCbwQakWdsb2JhbACTeY4kFQEBAQEJCwoHEQQewwoFhUGEUjaIMg X-IronPort-AV: E=Sophos;i="4.56,395,1280700000"; d="scan'208";a="68059191" Received: from out2.smtp.messagingengine.com ([66.111.4.26]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 20 Sep 2010 21:35:43 +0200 Received: from compute1.internal (compute1.nyi.mail.srv.osa [10.202.2.41]) by gateway1.messagingengine.com (Postfix) with ESMTP id 8752E42A; Mon, 20 Sep 2010 15:35:41 -0400 (EDT) Received: from frontend1.messagingengine.com ([10.202.2.160]) by compute1.internal (MEProxy); Mon, 20 Sep 2010 15:35:41 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=messagingengine.com; h=message-id:date:from:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; s=smtpout; bh=Jc/FabMrk76RgZiRhlFhgdqYoL0=; b=IC3zLbGQc8PQ1ugCvpYcj3j7iiDFCUJTRYec8QswxB6pR3zyyAnrPl3W92iEp201m+XJWyJod7ppouDlI40eDlZwottguZZDo+pKwjMy661PFE/+zHhIlu4diBhCxsP1ppqpsOouGK7yIZ50syFCB5XvPeBj7tQx7PYnzxaq5ac= X-Sasl-enc: m3iumMz6YehMjoIvGhhHE2m3pbyVGFeXoEaVlX1qSZx6 1285011341 Received: from [192.168.1.61] (64-71-1-165.static.wiline.com [64.71.1.165]) by mail.messagingengine.com (Postfix) with ESMTPSA id E44FC40A3BA; Mon, 20 Sep 2010 15:35:40 -0400 (EDT) Message-ID: <4C97B78B.5020108@ens-lyon.org> Date: Mon, 20 Sep 2010 12:35:39 -0700 From: Martin Jambon User-Agent: Thunderbird 2.0.0.22 (X11/20090908) MIME-Version: 1.0 To: Dumitru Potop-Butucaru Cc: caml-list@inria.fr Subject: code duplication (was Re: [Caml-list] How can I set a type parameter of Map.Make(X) ?) References: <4C97714A.6050403@inria.fr> <4C97991F.7030503@inria.fr> <4C97A0BF.1020003@ens-lyon.org> <4C97AFE2.9000809@inria.fr> In-Reply-To: <4C97AFE2.9000809@inria.fr> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ens-lyon:01 mli:01 compiler:01 mli:01 compiler:01 foo:01 val:01 val:01 bool:01 bool:01 iter:01 foo:01 int's:01 browsed:01 beginner's:01 Dumitru Potop-Butucaru wrote: > > Yes, but this involves duplicating code, and I really hate to duplicate > code, even in interfaces. We could also argue that writing interfaces in general is code duplication. Duplicating source code or data is bad only if future bugs and enhancements are not guaranteed to be applied to all the copies. It's not the case here because if the Map module of the standard library ever changes in an incompatible way, your .ml will no longer be compatible with your .mli and the compiler will not let this pass. Duplicating the comments of the standard map.mli may however not such a good idea because as always the compiler ignores them. Adding something like (* See the documentation of the standard Map module *) seems reasonable to me. Martin > To also answer Ashish: I want to define an interface to modules where I > use a very specific kind of map. Of course, I could leave Map.Make > polymorphic, but that is a different module type than the one I want to > use to represent my theory. > > Yours, > Jacky > > > On 20/09/2010 19:58, Martin Jambon wrote: >> Dumitru Potop-Butucaru wrote: >>> Actually, I was looking for a way to specialize a whole module, >>> not just the associated type (**this** I knew how to do). >>> I would like to write something like: >>> >>> include module type of Set.Make(String) with 'a= int >>> >>> Is this possible? >> I don't know about such a shortcut, but the following works and the >> interface >> is easier to use for a human: >> >> (* foo.mli *) >> type key = string >> type value = string >> type map >> val empty : map >> val is_empty : map -> bool >> val add : key -> value -> map -> map >> val find : key -> map -> value >> val remove : key -> map -> map >> val mem : key -> map -> bool >> val iter : (key -> value -> unit) -> map -> unit >> val map : (value -> value) -> map -> map >> val mapi : (key -> value -> value) -> map -> map >> val fold : (key -> value -> 'a -> 'a) -> map -> 'a -> 'a >> val compare : (value -> value -> int) -> map -> map -> int >> val equal : (value -> value -> bool) -> map -> map -> bool >> >> >> (* foo.ml *) >> module M = Map.Make (String) >> include M >> type value = string >> type map = string M.t >> >> >> >> Martin >> >> >>> Yours, >>> Jacky Potop >>> >>> >>> >>> >>> On 20/09/2010 16:57, Ashish Agarwal wrote: >>>> module M = Map.Make(String) >>>> >>>> type t = int M.t >>>> >>>> Type t is the type of maps from string's to int's. Or alternatively >>>> write a >>>> function that assumes 'a is some specific type: >>>> >>>> # let f m = M.fold (fun _ x y -> x + y) m 0;; >>>> val f : int M.t -> int = >>>> >>>> >>>> On Mon, Sep 20, 2010 at 10:35 AM, Dumitru Potop-Butucaru< >>>> dumitru.potop_butucaru@inria.fr> wrote: >>>> >>>>> Hello, >>>>> >>>>> I'm certain most users here will consider the question trivially >>>>> simple, >>>>> but I browsed the documentation without finding a solution. >>>>> >>>>> The question is quite general: Given a polymorphic definition like >>>>> Map.Make(X), where >>>>> X is some module, how can I specialize its 'a type parameter, e.g. by >>>>> setting it to Y, so that >>>>> I have maps from X to Y ? >>>>> >>>>> Yours, >>>>> Jacky Potop >>>>> >>>>> _______________________________________________ >>>>> Caml-list mailing list. Subscription management: >>>>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list >>>>> Archives: http://caml.inria.fr >>>>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >>>>> Bug reports: http://caml.inria.fr/bin/caml-bugs >>>>> >>>>> >>> _______________________________________________ >>> Caml-list mailing list. Subscription management: >>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list >>> Archives: http://caml.inria.fr >>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >>> Bug reports: http://caml.inria.fr/bin/caml-bugs >> > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs -- http://mjambon.com/