Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* 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

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