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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 85A4BBC57 for ; Mon, 20 Sep 2010 19:58:27 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApgAAEo9l0xCbwQakWdsb2JhbACTd44kFQEBAQEJCwoHEQQewjMFhUGEUjaIMg X-IronPort-AV: E=Sophos;i="4.56,394,1280700000"; d="scan'208";a="69836376" Received: from out2.smtp.messagingengine.com ([66.111.4.26]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 20 Sep 2010 19:58:26 +0200 Received: from compute3.internal (compute3.nyi.mail.srv.osa [10.202.2.43]) by gateway1.messagingengine.com (Postfix) with ESMTP id 8929D210; Mon, 20 Sep 2010 13:58:25 -0400 (EDT) Received: from frontend1.messagingengine.com ([10.202.2.160]) by compute3.internal (MEProxy); Mon, 20 Sep 2010 13:58:25 -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=IuCFAD9PEhj7WFI12HdXSPhTtxM=; b=V0eXb7HnLaWY/plv+xJQXJRPMOnPJCnPSqgDU5hmiKysxoe8BxHMgvCwogb2oiD+c4XKs7pVrdEC24Fg/ouBUq9HnhRlSKXy7+pDHb+9MVAVo+rWGgcaDpB6mSx0FPUCJUJsHbQDe0PwuLBHavRUg8TxfGW4QCyMIbZeZUBy3Bg= X-Sasl-enc: KmETgf8Ktu1zjUofBZ1yztzIO5yjIdUcYwj4AQP1p28L 1285005505 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 1B85E406460; Mon, 20 Sep 2010 13:58:25 -0400 (EDT) Message-ID: <4C97A0BF.1020003@ens-lyon.org> Date: Mon, 20 Sep 2010 10:58:23 -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: Re: [Caml-list] How can I set a type parameter of Map.Make(X) ? References: <4C97714A.6050403@inria.fr> <4C97991F.7030503@inria.fr> In-Reply-To: <4C97991F.7030503@inria.fr> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ens-lyon:01 foo:01 mli:01 val:01 val:01 bool:01 bool:01 iter:01 foo:01 int's:01 browsed:01 beginner's:01 ocaml:01 bug:01 beginner's:01 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 -- http://mjambon.com/