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.1 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 6172CBBAF for ; Thu, 10 Sep 2009 17:56:22 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmABAG++qEpCbwQZk2dsb2JhbACbPgEBAQEJCQoJEwTDTQWEGIph X-IronPort-AV: E=Sophos;i="4.44,365,1249250400"; d="scan'208";a="32541428" Received: from out1.smtp.messagingengine.com ([66.111.4.25]) by mail2-smtp-roc.national.inria.fr with ESMTP; 10 Sep 2009 17:56:21 +0200 Received: from compute1.internal (compute1.internal [10.202.2.41]) by gateway1.messagingengine.com (Postfix) with ESMTP id D5FCD67B84; Thu, 10 Sep 2009 11:56:20 -0400 (EDT) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute1.internal (MEProxy); Thu, 10 Sep 2009 11:56:20 -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=GRehyap+0YCOV9dUKey6QecSdLE=; b=Xkqm94RWqhcCwYlVnAOg363ttJaYzszWzBYjUMoUy+UOkMEIChalLboMV/w7nlVmrc3Ua/Qhu25DAbiOfE/pUlFr3aF4T1nnsKDexJoi2OxReP/lRBxYyCQfPnJZ4jellyPi1lFmyU8GfcyHKHQHgdNcJM8iCl3VzCHoRd/d8DQ= X-Sasl-enc: Nk6GkOL0Wv4weStuuWsORUS5yT22Hd1wSJd+8lQPXZ7x 1252598180 Received: from [192.168.1.15] (ALyon-157-1-94-122.w90-41.abo.wanadoo.fr [90.41.77.122]) by mail.messagingengine.com (Postfix) with ESMTPSA id 1D292B9C2; Thu, 10 Sep 2009 11:56:19 -0400 (EDT) Message-ID: <4AA91FE6.4050102@ens-lyon.org> Date: Thu, 10 Sep 2009 17:48:54 +0200 From: Martin Jambon User-Agent: Thunderbird 2.0.0.22 (X11/20090908) MIME-Version: 1.0 To: Will M Farr Cc: caml-list@inria.fr Subject: Re: [Caml-list] A (Silly?) Question About Universal Type Quantification References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ens-lyon:01 pervasives:01 functor:01 struct:01 forall:01 struct:01 forall:01 functor:01 designation:98 unbound:01 polymorphic:01 polymorphic:01 wrote:01 caml-list:01 functions:01 Will M Farr wrote: > Hello, > > I recently encountered a situation where I had (effectively) the > following polymorphic type: > > type 'a record = { id : int; data : 'a } You could do this: type record = { id : int; data : 'a . 'a } The only minor problem is that you can't create values of such type :-) > and the following compare function > > let compare {id = id1} {id = id2} = Pervasives.compare id1 id2 > > and wanted to put such records into a set. However, I could not figure > out how to make the polymorphic 'a in the type definition "disappear" in > the module argument to the Set.Make functor. For example, the obvious > > Set.Make(struct > type t = 'a record > let compare = compare > end) > > fails because the 'a in the type definition for t is unbound. Is there > no way to do this? I'm thinking of some sort of "forall" designation, > which universally quantifies the type parameter, like > > Set.Make(struct > type t = forall 'a : 'a record > let compare = compare > end) > > (I'm sure that there is better terminology for this---please pardon my > ignorance about types and type theory.) > > I ended up solving my problem by placing the record type into a functor, > whose argument specified the concrete type for data, but I'm curious if > other solutions exist. Looks like the right approach. You could also used a defunctorized version of Set, at the cost of losing the static guarantee that you won't mix sets using inconsistent comparison functions. Martin -- http://mjambon.com/