Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Damien <Damien.Pous@ens-lyon.fr>
To: caml-list@pauillac.inria.fr
Subject: [Caml-list] typing class...
Date: Sun, 30 Mar 2003 21:12:38 +0200	[thread overview]
Message-ID: <20030330211238.6b499e17.Damien.Pous@ens-lyon.fr> (raw)

[-- 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

             reply	other threads:[~2003-03-30 19:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-30 19:12 Damien [this message]
2003-04-03  2:20 ` Jacques Garrigue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030330211238.6b499e17.Damien.Pous@ens-lyon.fr \
    --to=damien.pous@ens-lyon.fr \
    --cc=caml-list@pauillac.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox