Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: circular types?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Max Skaller <skaller@o...>
Subject: Re: circular types?
Hendrik Tews wrote:

> John Max Skaller writes:

>    I think this can be done now. Here is the method: to have a type t
>    and a class c mutually dependent, for example:
> 
>         class type c = object x : t end
>         and type  t = C c | Null
> 
>    write
> 
>         class type c' ['t] = object x : 't end
>         type t = C t c' | Null
>         class type c = t c'
> 
> 
> Yes, this is the theoretical answer. But this just doesn't work
> out in anything bigger than a tutorial example. I am involved in
> programming a logic compiler. We have about 40 variant types and
> at least 10 classes. 

	I have used this technique in Vyper (my implementation
of Python in Ocaml). While it is probably smaller than your logic
compiler:
there are 10 public class types, and about 20 variants --- the word
'and' occurs 33 times in the .mli file --- it would seem to be in the
same league. The interface file is 500 lines.

> If my design were not constraint by the
> abilities of the ocaml compiler some of the classes were in
> mutual recursion with the bigger halve of the variant types. So
> you are not telling me seriously I should write classes with 10
> type variables!

	Sure! 10 type variables adds one line to each class. 
(if you use very short names :-)

> Just for curiosity: Does somebody use the above workaround in a
> project with more than 10.000 lines of ocaml code? (We do, but
> every typing error is a nightmare.)

	Vyper consists of 25,000 lines of .ml files and
5000 lines of .mli files. 
	
-- 
John (Max) Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net