From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@lri.fr>
To: luther@dpt-info.u-strasbg.fr
Cc: caml-list@inria.fr
Subject: Re: Modules, type de modules et type polymorphes.
Date: Wed, 20 Sep 2000 09:31:55 +0200 (MEST) [thread overview]
Message-ID: <14792.26603.589374.730149@pc803> (raw)
In-Reply-To: <20000919142939.A3312@lambda.u-strasbg.fr>
> quel est le probleme de ceci ?
> What is the problem with the following ?
>
> bash-2.04$ ocaml
> Objective Caml version 3.00
>
> # 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
Une fonction de type int -> string ne peut pas être appelée avec un
argument d'un type quelconque. Donc votre module A ne peut avoir
l'interface T_A qui déclare que string_of_a accepte un argument d'un
type quelconque.
Dit autrement, si le module A était effectivement de type T_A, alors
A.string_of_a aurait le type 'a -> string et je pourrais écrire
A.string_of_a "tagada", qui n'a pas de sens.
Plus précisément, et c'est peut-être là l'origine de votre problème,
la quantification universelle sur 'a est faite au niveau du type de
string_of_a (et de manière plus générale pour chaque déclaration dans
la signature) et non au niveau du type de module. En ce sens, il n'y a
pas de polymorphisme au niveau du langage de module.
En revanche, vous pouvez écrire
module type T_A = sig
type a
val string_of_a : a -> string
end
puis
module A : T_A = struct
type a = int
let string_of_a = string_of_int
end
[ No English translation, I apologize. ]
--
Jean-Christophe FILLIATRE
mailto:Jean-Christophe.Filliatre@lri.fr
http://www.lri.fr/~filliatr
next prev parent reply other threads:[~2000-09-20 19:52 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
2000-09-20 7:31 ` Jean-Christophe Filliatre [this message]
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=14792.26603.589374.730149@pc803 \
--to=jean-christophe.filliatre@lri.fr \
--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