Version française
Home     About     Download     Resources     Contact us    
Browse thread
problemes de types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jean-Claude Laffitte <laffitte@y...>
Subject: problemes de types
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.