module, module type et foncteurs, ...

From: Sven LUTHER (luther@maxime.u-strasbg.fr)
Date: Fri Oct 22 1999 - 16:03:04 MET DST


Date: Fri, 22 Oct 1999 16:03:04 +0200
From: Sven LUTHER <luther@maxime.u-strasbg.fr>
To: caml-list@inria.fr
Subject: module, module type et foncteurs, ...

Bonjour, ...

Je souhaite ecrire quelque chose du genre :

-----------------------------------------------------------
module A = struct
  type a = A | B | C
  let id (x : a) = x
end

module type T_A = sig
  type a
  val id : a -> a
end
module type T_A_detail = sig
  type a = A | B | C
end
module type T_A_choisi = T_A
module type T_B = sig
  type a
  type b =
    | TA of A.a
    | TB of b
end
module type T_Make_B = functor (A : T_A_choisi) -> T_B
module Make_B (A : T_A_choisi) = struct
  type a = A.a
  type b =
    | TA of A.a
    | TB of b
end
module Make_C (A : T_A_detail) (Make_B : T_Make_B) = struct
  let string_of_a = function
    | A.A -> "A"
    | A.B -> "B"
    | A.C -> "C"
end
module B2 = Make_B (A)
module C2 = Make_C (A) (Make_B)
let rec string_of_b = function
  | B2.TA a -> B2.string_of_a a
  | B2.TB b -> string_of_b b
-----------------------------------------------------------

Mais j'obtient l'erreur suivante :

-----------------------------------------------------------
File "exemple.ml", line 35, characters 24-30:
Signature mismatch:
Modules do not match:
  functor(A : T_A_choisi) ->
    sig type a = A.a and b = Make_B(A).b = | TA of A.a | TB of b end
is not included in
  T_Make_B
Modules do not match:
  sig type a = A.a and b = Make_B(A).b = | TA of A.a | TB of b end
is not included in
  T_B
Type declarations do not match:
  type b = Make_B(A).b = | TA of A.a | TB of b
is not included in
  type b = | TA of A.a | TB of b
-----------------------------------------------------------

Est-ce normal, que ce passe-t-il exactement. Y a-t-il une autre maniere
de faire la meme chose ?

Je ne comprend pas qu'elle est la difference entre
  type b = Make_B(A).b = | TA of A.a | TB of b
et
  type b = | TA of A.a | TB of b

D'un autre cote est-ce qu'un type de tableau de booleens qui serait represente de
maniere efficace existe ? on aurrait un bit par booleen, et non un int comme cela est
fait actuellement.

J'imagine qu'on peut faire cela en definissant un type de tableau d'entier, et aller
voir la valeur de chaque bit de ces entiers.

Amicalement,

Sven LUTHER



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