* problemes de types
@ 1997-07-21 14:49 Jean-Claude Laffitte
1997-07-22 7:29 ` Pierre Weis
0 siblings, 1 reply; 2+ messages in thread
From: Jean-Claude Laffitte @ 1997-07-21 14:49 UTC (permalink / raw)
To: caml-list
j'ai un petit probleme avec les definitions de types. Lorsque je definis deux
types enregistrements ayant un champ portant le meme nom, le compilateur
semble avoir du mal a reconnaitre les types de mes variables.
voici un exemple :
Ex1 :
(*------------------------------------------------------------------*)
type var = {
mutable id : int;
mutable date : int
}
type alrm = {
mutable acq : bool;
mutable id : int;
mutable valeur : string
}
let test (a : var) (b : alrm) =
if ( a.date = 100) then print_string b.valeur;
if ( a.id = 10 ) then print_int b.id
(*------------------------------------------------------------------*)
File "t1.ml", line 15, characters 7-8:
This expression has type var but is here used with type alrm
Ne peut on pas definir deux types ayant un champ de meme nom ou est ce qu'un
detail m'aurait echappe ??
Le meme type de conflit existe avec les types enumeres.
Ex2 :
(*------------------------------------------------------------------*)
type var = Ident | Date
type alrm = Acq | Ident | Valeur
let test (a : var) =
match a with
Ident -> ();
| Date -> ()
(*------------------------------------------------------------------*)
File "t2.ml", line 7, characters 4-9:
This pattern matches values of type alrm
but is here used to match values of type var
**********************************************************************
English summary
**********************************************************************
I've a little problem with record types. When I define two types with a common
field name, the compiler seems to have problems to recognize the type of
variables.
See Ex1.
The same problems appears with variant types.
See Ex2.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: problemes de types
1997-07-21 14:49 problemes de types Jean-Claude Laffitte
@ 1997-07-22 7:29 ` Pierre Weis
0 siblings, 0 replies; 2+ messages in thread
From: Pierre Weis @ 1997-07-22 7:29 UTC (permalink / raw)
To: laffitte; +Cc: caml-list
> j'ai un petit probleme avec les definitions de types. Lorsque je definis deux
> types enregistrements ayant un champ portant le meme nom, le compilateur
> semble avoir du mal a reconnaitre les types de mes variables.
[...]
> Le meme type de conflit existe avec les types enumeres.
Effectivement, il n'y a pas de surcharge sur les identificateurs en
Caml. C'est vrai pour les noms de champs d'enregistrement, les
constructeurs de types somme, les identificateurs de valeurs et les
ope'rateurs (pas de surcharge de + par exemple). Seuls les objets
d'O'Caml permettent cette surcharge sur les me'thodes.
Si vous voulez de'finir des champs de me^me nom dans plusieurs types
diffe'rents, il faut les de'finir dans des modules diffe'rents,
puisque chaque module introduit son propre espace de nom.
> **********************************************************************
> English summary
> **********************************************************************
> I've a little problem with record types. When I define two types with a common
> field name, the compiler seems to have problems to recognize the type of
> variables.
[...]
> The same problems appears with variant types.
There is no overloading in Caml, neither for field names in records,
constructors names in concrete types nor for functions or operators
names (e.g. +). However, objects in O'Caml provide overloading for
methods names.
A solution to overcome the problem is to define the types in separate
modules, since each module introduce a new space name.
Best regards,
Pierre Weis
INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1997-07-22 7:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-07-21 14:49 problemes de types Jean-Claude Laffitte
1997-07-22 7:29 ` Pierre Weis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox