* [Caml-list] typing class...
@ 2003-03-30 19:12 Damien
2003-04-03 2:20 ` Jacques Garrigue
0 siblings, 1 reply; 2+ messages in thread
From: Damien @ 2003-03-30 19:12 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 3119 bytes --]
hello,
I am not sure this is a bug, but this is annoying...
I want to define two class, whose types are mutually recursive
and grow along the different layers of my project :
I simplified the code a lot, please don't say "that's dummy code"...
so let <types.mli> be this horrible file :
> (* [*_vt] means "virtual class type", and [*_t] means "class type" *)
>
> (* initial class types for a and b *)
>
>class type virtual ['a, 'b] a_vt = object
> constraint 'a = ('a, 'b) #a_t
> constraint 'b = ('a, 'b) #b_t
> method virtual coerce: 'a
> method as_a: ('a, 'b) a_t
>end
>and virtual ['a, 'b] b_vt = object
> constraint 'a = ('a, 'b) #a_t
> constraint 'b = ('a, 'b) #b_t
> method virtual coerce: 'b
> method as_b: ('a, 'b) b_t
>end
>
>and ['a, 'b] a_t = object
> inherit ['a, 'b] a_vt
> method coerce: 'a
>end
>and ['a, 'b] b_t = object
> inherit ['a, 'b] b_vt
> method coerce: 'b
>end
>
>(* some layers higher : classes have grown *)
>
>class type virtual ['a, 'b] a_k_vt =
>object
> constraint 'a = ('a, 'b) #a_k_t
> constraint 'b = ('a, 'b) #b_k_t
> inherit ['a, 'b] a_vt
> method as_a_k: ('a, 'b) a_k_t
>end
>and virtual ['a, 'b] b_k_vt =
>object
> constraint 'a = ('a, 'b) #a_k_t
> constraint 'b = ('a, 'b) #b_k_t
> inherit ['a, 'b] b_vt
> method as_b_k: ('a, 'b) b_k_t
>end
>and ['a, 'b] a_k_t = object
> inherit ['a, 'b] a_k_vt
> method coerce: 'a
>end
>and ['a, 'b] b_k_t = object
> inherit ['a, 'b] b_k_vt
> method coerce: 'b
>end
let's then implement in <ab.ml> :
>open Types
>
>(* initial classes *)
>class virtual ['a, 'b] a : ['a, 'b] a_vt =
>object (self)
> method as_a = (self :> ('a, 'b) a_t)
>end
>
>class virtual ['a, 'b] b : ['a, 'b] b_vt =
>object (self)
> method as_b = (self :> ('a, 'b) b_t)
>end
>
>(* taller classes *)
>class virtual ['a, 'b] a_k : ['a, 'b] a_k_vt =
>object (self)
> inherit ['a, 'b] a
> method as_a_k = (self :> ('a, 'b) a_k_t)
>end
>
>class virtual ['a, 'b] b_k : ['a, 'b] b_k_vt =
>object (self)
> inherit ['a, 'b] b
> method as_b_k = (self :> ('a, 'b) b_k_t)
>end
within the toplevel, this works fine,
but let's have an interface file <ab.mli> :
>open Types
>
>class virtual ['a, 'b] a : ['a, 'b] a_vt
>class virtual ['a, 'b] b : ['a, 'b] b_vt
>
>class virtual ['a, 'b] a_k : ['a, 'b] a_k_vt
>class virtual ['a, 'b] b_k : ['a, 'b] b_k_vt
when I compile, I get :
>ocamlc -c types.mli
>ocamlc -c ab.mli
>ocamlc -c ab.ml
>The implementation ab.ml does not match the interface ab.cmi:
>Type declarations do not match:
> type ('a, 'b) b_k =
> < as_b : ('a, 'b) Types.b_t; as_b_k : ('a, 'b) Types.b_k_t; coerce
> :'b > constraint 'a = ('a, 'b) #Types.a_k_t
> constraint 'b = ('a, 'b) #Types.b_k_t
>is not included in
> type ('a, 'b) b_k =
> < as_b : ('a, 'b) Types.b_t; as_b_k : ('a, 'b) Types.b_k_t; coerce
> :'b > constraint 'a = ('a, 'b) #Types.a_k_t
> constraint 'b = ('a, 'b) #Types.b_k_t
>make: *** [all] Erreur 2
grmpf...
I've found an other solution for my code, but, I think there's a problem
on somewhere !
Any explanation !?
Thanks,
damien
<http://www.ens-lyon.fr/~dpous/>
[-- Attachment #2: Makefile --]
[-- Type: application/octet-stream, Size: 61 bytes --]
all:
ocamlc -c types.mli
ocamlc -c ab.mli
ocamlc -c ab.ml
[-- Attachment #3: types.mli --]
[-- Type: application/octet-stream, Size: 985 bytes --]
class type virtual ['a, 'b] a_vt = object
constraint 'a = ('a, 'b) #a_t
constraint 'b = ('a, 'b) #b_t
method virtual coerce: 'a
method as_a: ('a, 'b) a_t
end
and virtual ['a, 'b] b_vt = object
constraint 'a = ('a, 'b) #a_t
constraint 'b = ('a, 'b) #b_t
method virtual coerce: 'b
method as_b: ('a, 'b) b_t
end
and ['a, 'b] a_t = object
inherit ['a, 'b] a_vt
method coerce: 'a
end
and ['a, 'b] b_t = object
inherit ['a, 'b] b_vt
method coerce: 'b
end
class type virtual ['a, 'b] a_k_vt =
object
constraint 'a = ('a, 'b) #a_k_t
constraint 'b = ('a, 'b) #b_k_t
inherit ['a, 'b] a_vt
method as_a_k: ('a, 'b) a_k_t
end
and virtual ['a, 'b] b_k_vt =
object
constraint 'a = ('a, 'b) #a_k_t
constraint 'b = ('a, 'b) #b_k_t
inherit ['a, 'b] b_vt
method as_b_k: ('a, 'b) b_k_t
end
and ['a, 'b] a_k_t = object
inherit ['a, 'b] a_k_vt
method coerce: 'a
end
and ['a, 'b] b_k_t = object
inherit ['a, 'b] b_k_vt
method coerce: 'b
end
[-- Attachment #4: ab.mli --]
[-- Type: application/octet-stream, Size: 195 bytes --]
open Types
class virtual ['a, 'b] a : ['a, 'b] a_vt
class virtual ['a, 'b] b : ['a, 'b] b_vt
class virtual ['a, 'b] a_k : ['a, 'b] a_k_vt
class virtual ['a, 'b] b_k : ['a, 'b] b_k_vt
[-- Attachment #5: ab.ml --]
[-- Type: application/octet-stream, Size: 478 bytes --]
open Types
class virtual ['a, 'b] a : ['a, 'b] a_vt =
object (self)
method as_a = (self :> ('a, 'b) a_t)
end
class virtual ['a, 'b] b : ['a, 'b] b_vt =
object (self)
method as_b = (self :> ('a, 'b) b_t)
end
class virtual ['a, 'b] a_k : ['a, 'b] a_k_vt =
object (self)
inherit ['a, 'b] a
method as_a_k = (self :> ('a, 'b) a_k_t)
end
class virtual ['a, 'b] b_k : ['a, 'b] b_k_vt =
object (self)
inherit ['a, 'b] b
method as_b_k = (self :> ('a, 'b) b_k_t)
end
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] typing class...
2003-03-30 19:12 [Caml-list] typing class Damien
@ 2003-04-03 2:20 ` Jacques Garrigue
0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2003-04-03 2:20 UTC (permalink / raw)
To: Damien.Pous; +Cc: caml-list
From: Damien <Damien.Pous@ens-lyon.fr>
> I am not sure this is a bug, but this is annoying...
This looks like a bug, this smells like a bug... and this is a bug!
Thanks for the report, this is now fixed.
I join a patch which should apply on any recent ocaml.
Jacques Garrigue
Index: typing/ctype.ml
===================================================================
RCS file: /net/pauillac/caml/repository/csl/typing/ctype.ml,v
retrieving revision 1.154
retrieving revision 1.155
diff -c -r1.154 -r1.155
*** ctype.ml 2003/03/26 07:24:17 1.154
--- ctype.ml 2003/04/03 02:15:38 1.155
***************
*** 2058,2063 ****
--- 2058,2068 ----
(* Equivalence between parameterized types *)
(*********************************************)
+ let normalize_subst subst =
+ if List.exists
+ (function {desc=Tlink _}, _ | _, {desc=Tlink _} -> true | _ -> false)
+ !subst
+ then subst := List.map (fun (t1,t2) -> repr t1, repr t2) !subst
let rec eqtype rename type_pairs subst env t1 t2 =
if t1 == t2 then () else
***************
*** 2069,2074 ****
--- 2074,2080 ----
match (t1.desc, t2.desc) with
(Tvar, Tvar) when rename ->
begin try
+ normalize_subst subst;
if List.assq t1 !subst != t2 then raise (Unify [])
with Not_found ->
subst := (t1, t2) :: !subst
***************
*** 2088,2093 ****
--- 2094,2100 ----
match (t1'.desc, t2'.desc) with
(Tvar, Tvar) when rename ->
begin try
+ normalize_subst subst;
if List.assq t1' !subst != t2' then raise (Unify [])
with Not_found ->
subst := (t1', t2') :: !subst
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-04-03 2:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-30 19:12 [Caml-list] typing class Damien
2003-04-03 2:20 ` Jacques Garrigue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox