From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA06532 for caml-red; Wed, 20 Sep 2000 21:50:12 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA21055 for ; Tue, 19 Sep 2000 20:16:28 +0200 (MET DST) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by nez-perce.inria.fr (8.10.0/8.10.0) with ESMTP id e8JIGRT16473 for ; Tue, 19 Sep 2000 20:16:27 +0200 (MET DST) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id UAA22380; Tue, 19 Sep 2000 20:16:26 +0200 (MET DST) Date: Tue, 19 Sep 2000 20:16:26 +0200 From: Markus Mottl To: Sven LUTHER , caml-list@inria.fr Subject: Re: Modules, type de modules et type polymorphes. Message-ID: <20000919201626.A18274@miss.wu-wien.ac.at> References: <20000919142939.A3312@lambda.u-strasbg.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2i In-Reply-To: <20000919142939.A3312@lambda.u-strasbg.fr>; from luther@dpt-info.u-strasbg.fr on Tue, Sep 19, 2000 at 14:29:39 +0200 Sender: weis@pauillac.inria.fr On Tue, 19 Sep 2000, Sven LUTHER wrote: > What is the problem with the following ? > > # module type T_A = sig > val string_of_a : 'a -> string > end;; > module type T_A = sig val string_of_a : 'a -> string end > # module A : T_A = struct > let string_of_a = string_of_int > end;; > Signature mismatch: > Modules do not match: > sig val string_of_a : int -> string end > is not included in > T_A > Values do not match: > val string_of_a : int -> string > is not included in > val string_of_a : 'a -> string The reaction of OCaml looks correct to me: you have a signature that demands that there be a function "string_of_a" which can convert a string out of anything (I'd really love to have something like this! ;) The implementation, however, can only manage integers, which means: it is not general enough to cope with all input. Just imagine that somebody, believing that your function can handle all input as specified in the interface, passed a float to the implementation "A.string_of_a": it might crash on this input. Therefore, this is not allowed. You could do the opposite: have a signature that restricts the type to integers, but whose implementation could handle much more than this. This would be safe. Best regards, Markus Mottl -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl