From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: Sven LUTHER <luther@dpt-info.u-strasbg.fr>, caml-list@inria.fr
Subject: Re: Modules, type de modules et type polymorphes.
Date: Tue, 19 Sep 2000 20:16:26 +0200 [thread overview]
Message-ID: <20000919201626.A18274@miss.wu-wien.ac.at> (raw)
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
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
next prev parent reply other threads:[~2000-09-20 19:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-09-19 12:29 Sven LUTHER
2000-09-19 18:16 ` Markus Mottl [this message]
2000-09-20 7:31 ` Jean-Christophe Filliatre
2000-09-20 13:45 ` Sylvain BOULM'E
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20000919201626.A18274@miss.wu-wien.ac.at \
--to=mottl@miss.wu-wien.ac.at \
--cc=caml-list@inria.fr \
--cc=luther@dpt-info.u-strasbg.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox