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=1.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 128AEBC69 for ; Sun, 15 Oct 2006 05:29:06 +0200 (CEST) Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.186]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k9F3T5ce016901 for ; Sun, 15 Oct 2006 05:29:05 +0200 Received: by nf-out-0910.google.com with SMTP id y38so1955006nfb for ; Sat, 14 Oct 2006 20:29:05 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=OyyjkHJrzu+3CHcYpkMIKjaV5Cq7YaCensita8j1UBYNCYqtAKb1dJOytbItQ0Nn8WG0jEDCvw+ynoC+kCDSX8EpAcRKmP9XvI6r3pxaB0cdA20oIkRVTxpk+AubhgTjAYMWUnEYbSGezuPPBTI4i0pnjp5LK4RVA5PLAl7M8dM= Received: by 10.78.188.19 with SMTP id l19mr5919565huf; Sat, 14 Oct 2006 20:29:04 -0700 (PDT) Received: by 10.78.100.6 with HTTP; Sat, 14 Oct 2006 20:29:04 -0700 (PDT) Message-ID: <6dbd4d000610142029m92d7005v65e95f031e7eae9b@mail.gmail.com> Date: Sat, 14 Oct 2006 23:29:04 -0400 From: "Denis Bueno" To: "OCaml Mailing List" Subject: Type error MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-j-chkmail-Score: MSGID : 4531AB01.000 on concorde : j-chkmail score : X : 0/20 1 X-Miltered: at concorde with ID 4531AB01.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; val:01 val:01 bool:01 cmi:01 compilable:01 compile:01 match:02 match:02 objects:02 similarly:03 let:03 library:03 fix:04 interface:05 interface:05 I'm writing a simple (stupid) de-functorised Set library. Its skeleton is: ,---- | type 'a t | (** The type of sets. *) | | val empty: 'a t | (** The empty set. *) | | val mem: 'a -> 'a t -> bool | (** [mem x s] tests whether [x] belongs to the set [s]. *) | | val add: 'a -> 'a t -> 'a t | (** [add x s] returns a set containing all elements of [s], | plus [x]. If [x] was already in [s], [s] is returned unchanged. *) `---- In my implementation, sets are lists. One of the things I'd like to do is write an of_array to create an array from a set. However, it is often the case that I have an array of objects from which I'd like to pull out one field & make a set of those fields. So, my of_array looks like this: Interface: ,---- | val of_array: ?getter : ('b -> 'a) -> 'b array -> 'a t | (** [of_array xs] returns a set containing the elements in [xs]. *) `---- Implementation: ,---- | let of_array ?(getter = fun x -> x) xs = | Array.fold_right (fun x set -> add (getter x) set) xs empty;; `---- I get a type error when trying to compile this. I don't know how to fix it, or even if it's possible without wrecking my nice of_array signature. The type error: ,---- | The implementation pSet.ml does not match the interface pSet.cmi: | Values do not match: | val of_array : ?getter:('a -> 'a) -> 'a array -> 'a list | is not included in | val of_array : ?getter:('a -> 'b) -> 'a array -> 'b t `---- I understand why this shouldn't be compilable, but, is it possible to do something similarly elegant (without creating a separate function)? -Denis