Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Mutually recursive types and classes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: brogoff@s...
Subject: Re: [Caml-list] Mutually recursive types and classes
You can use the parameterization trick and introduce an extra type variable, 
as has been discussed on the list before. This is the big hammer for solving 
all sorts of forbidden recurrences in OCaml, like the functor instance/type 
recurrence. Thankfully, that particular problem now appears to be fixed in the 
CVS snapshot. 

You can also have recursion between object types and types, and use coercion 
to make sure everything matches, like so 

type a = A of (b -> unit) | B
and b = < f : a -> unit > 

class c = 
  object(this) method f = function A foo -> foo (this :> b) | _ -> () end 

-- Brian


On Thu, 19 Jun 2003, Nick Name wrote:

> Hi all,
> 
> I wish to declare a type like
> 
> type a = A of (b -> unit) | ...
> 
> where b is a class like
> 
> class b = 
> object (this)
> 	method f : a -> unit = 
> 		function 
> 		  A f -> f this
>                 | _ -> unit
> end
> 
> or, alternatively:
> 
> class b =
> object 
>    inherit [a] otherclass
>    ...
> end
> 
> How can I do such a thing, considering that I can't write an "and"
> keyword between a type declaration and a class (or class type)
> declaration?
> 
> Thanks for help
> 
> Vincenzo
> 
> -------------------
> 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
> 

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