problemes de types

From: Jean-Claude Laffitte (laffitte@yeti2.didac-mip.fr)
Date: Mon Jul 21 1997 - 16:49:03 MET DST


Message-Id: <199707211449.QAA02229@yeti2.didac-mip.fr>
To: caml-list@inria.fr
Subject: problemes de types
Date: Mon, 21 Jul 1997 16:49:03 +0200
From: Jean-Claude Laffitte <laffitte@yeti2.didac-mip.fr>

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.



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:11 MET