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.0 required=5.0 tests=none autolearn=disabled version=3.1.3 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 8BD33BC69 for ; Fri, 4 Jan 2008 09:24:48 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAGZ8fUfAXQInh2dsb2JhbACQEAEBAQgKKZo6 X-IronPort-AV: E=Sophos;i="4.24,244,1196636400"; d="scan'208";a="20892374" Received: from concorde.inria.fr ([192.93.2.39]) by mail4-smtp-sop.national.inria.fr with ESMTP; 04 Jan 2008 09:24:48 +0100 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m048OltF015437 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 4 Jan 2008 09:24:48 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAALR7fUcjCUuEn2dsb2JhbACQEAEBAQEHBAYJIJo6 X-IronPort-AV: E=Sophos;i="4.24,244,1196636400"; d="scan'208";a="5714167" Received: from sys32.mail.msu.edu ([35.9.75.132]) by mail2-smtp-roc.national.inria.fr with ESMTP; 04 Jan 2008 09:24:47 +0100 Received: from c-67-167-176-8.hsd1.mi.comcast.net ([67.167.176.8] helo=[192.168.1.4]) by sys32.mail.msu.edu with esmtpsa (Exim 4.63 #1) (TLSv1:AES256-SHA:256) id 1JAhrB-0000EU-WC for caml-list@inria.fr; Fri, 04 Jan 2008 03:24:46 -0500 Message-ID: <477DED41.3040009@msu.edu> Date: Fri, 04 Jan 2008 03:24:33 -0500 From: Jeff Shaw User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: caml-list@inria.fr Subject: restricting and hiding record fields for functors Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus: None found by Clam AV X-Miltered: at concorde with ID 477DED4F.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; restricting:01 functors:01 sig:01 val:01 functor:01 functor:01 checker:01 sig:01 val:01 getx:01 functions:01 modules:02 modules:02 match:02 archives:02 Hello. I searched through the Google archives of this list, so I apologize if I missed something relevant. I'm working on a project that uses record types, perhaps module type Cordinate = sig type ordinate type point2d = {x : ordinate; y : ordinate;} val distance : point2d -> float end Now I have a functor over modules that match the signature Coordinate, but I want to allow the modules given to the functor to have things in the record "point2d" besides just x and y. It seems the types in this case are really clear and there shouldn't be any ambiguity (but I'm no expert). As it is now, to use such records I have to entirely hide their contents so that the type checker doesn't complain when "point2d" contains extra fields. In addition, any fields I need access to in the functor will have an associated function for setting and getting the values. For instance, module type Cordinate1 = sig type ordinate type point2d val setx : ordinal -> point2d -> point2d val sety : ordinal -> point2d -> point2d val makepoint : ordinal -> ordinal -> point2d val getx : point2d -> ordinate val gety : point2d -> ordinate val getpoint : point2d -> ordinate * ordinate val distance : point2d -> float end This is really quite ugly. I would rather be able to have x and y in the signature and get rid of get/set functions. But then you can't have extra fields. You can't, for instance, hide them via a signature. Or perhaps I'm missing some simple technique? Please let me know. Thanks, Jeff