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 CAA00739; Mon, 15 Jul 2002 02:35: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 CAA00722 for ; Mon, 15 Jul 2002 02:35:01 +0200 (MET DST) Received: from postfix2-2.free.fr (postfix2-2.free.fr [213.228.0.140]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g6F0RZf25613 for ; Mon, 15 Jul 2002 02:27:39 +0200 (MET DST) Received: from lfs (strasbourg-2-a7-62-147-13-148.dial.proxad.net [62.147.13.148]) by postfix2-2.free.fr (Postfix) with SMTP id 3B89D5F763 for ; Mon, 15 Jul 2002 02:27:29 +0200 (CEST) Date: Mon, 15 Jul 2002 02:35:42 +0200 From: Nicolas FRANCOIS (AKA El Bofo) To: Caml List Subject: [Caml-list] About modules again Message-Id: <20020715023542.56e961fa.nicolas.francois@free.fr> X-Mailer: Sylpheed version 0.7.6 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I'd like to be able to define some polymorphic functions in module signatures. I explain it right now : I have some abstract modules (this is not my code, it seems to be a pre-project from Foc) : module type Set = sig type elem val (==) : elem -> elem -> bool (* equality *) val normalize : elem -> elem (* there may be more than one representation of each element in the set, this function may perform some simplification *) val print : elem -> unit (* printing (using the Format library) *) val write : formatter -> elem -> unit (* writing in file (using the Format library) *) val parse : char Stream.t -> elem val read : in_channel -> elem (* reading from file, compatible with write *) val write_bin : out_channel -> elem -> unit (* writing as binary value *) val read_bin : in_channel -> elem (* reading as binary value *) end module type Group = sig include Set val zero : elem (* zero ! *) val (++) : elem -> elem -> elem (* sum *) val (--) : elem -> elem -> elem (* subtraction *) val opp : elem -> elem (* opposite (0 -- x) *) end module type Ring = sig include Group val one : elem (* one ! *) val t_of_int : int -> elem (* the standard mapping from integer *) val ( ** ) : elem -> elem -> elem (* product *) val conjugate : elem -> elem (* conjugate value *) end So you see module type Ring implement the "methods" of Group. My problem is : the exponentiation (x -> x^i for a positive integer) can be accomplished with just the product, without knowledge of what the objects are. Next we define some Rings, filling the holes in the definitions : module Ring_Z = struct type elem = int type stathm = int let zero = 0 let one = 1 let t_of_int n = n let (++) = (+) let (--) = (-) let ( ** ) = ( * ) let ( == ) = ( = ) let opp x = - x let print = print_int let write ch = pp_print_int ch let parse = parse_int let read ch = parse (Stream.of_channel ch) let write_bin = output_value let read_bin = input_value let stathm = abs let less = (<) let (//) = (/) let (mod) = (mod) let div_mod x y = x / y, x mod y let normalize x = x let conjugate x = x end (it's an Euclidian Ring, but that's not the point). So you see my problem : I have to define a concrete method in an abstract module, just not to have to fill the definition for every new Ring I define. Is there a way to do this ? Or is this specific to objects ? \bye -- Nicolas FRANCOIS http://nicolas.francois.free.fr A TRUE Klingon programmer does NOT comment his code ------------------- 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