From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA02624; Tue, 22 Jul 2003 22:11:01 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA06515 for ; Tue, 22 Jul 2003 22:11:00 +0200 (MET DST) Received: from epexch01.qlogic.org ([63.170.40.3]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h6MKAxf20835 for ; Tue, 22 Jul 2003 22:10:59 +0200 (MET DST) Received: from epmailtmp.qlogic.org ([10.20.33.254]) by epexch01.qlogic.org with Microsoft SMTPSVC(5.0.2195.5329); Tue, 22 Jul 2003 15:09:12 -0500 Received: from [10.20.33.146] ([10.20.33.146]) by epmailtmp.qlogic.org with Microsoft SMTPSVC(5.0.2195.4905); Tue, 22 Jul 2003 15:10:05 -0500 Date: Tue, 22 Jul 2003 15:09:59 -0500 (CDT) From: Brian Hurt X-X-Sender: Reply-To: Brian Hurt To: Ocaml Mailing List Subject: [Caml-list] Variant parameterized method? Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-OriginalArrivalTime: 22 Jul 2003 20:10:05.0259 (UTC) FILETIME=[3DB811B0:01C3508D] X-Loop: caml-list@inria.fr X-Spam: no; 0.00; qlogic:01 foo:01 implemented:01 val:01 mli:01 incompatible:01 function-:01 behave:01 variant:02 abbreviation:02 compile:02 necessarily:02 stack:02 interface:03 wich:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk What I want to do is write a class interface like: class virtual ['a] foo : object method virtual doit : 'a method map : 'b. ('a -> 'b) -> 'b foo end The map function returns a new foo (not necessarily a new member of whatever derived from foo class the function is actually being called on) parameterized on the variant type. This would be implemented more or less like: class ['a] mapped_foo f_init e_init = object val f = f_init val e = e_init method doit = f (e#doit) method map g = let h x = g (f x) in mapped_foo g e end The first prototype, when I try to compile it, returns with: File "foo.mli", line 2, characters 6-100: The abbreviation foo is used with parameters 'a foo wich are incompatible with constraints 'b foo [sic on the wich- minor typo there]. It works just fine if I change map to return a 'b list, or 'b array, or 'b Stack.t- it seems to be just 'b foo that's a problem. Am I missing something? If not, what is the suggested way for doing this? I need map as a member function- it needs to behave differently on different types, and as I don't have reflextion, I need it to be a member function. I'd prefer to keep it as a class for taste reasons. Help is appreciated. Brian ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners