Browse thread
Re: circular types?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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: > I would like to have recursive types spread over different files > like > > ========== file types.ml > > type types = > | Product of types list > ... > | Comprehension of formula > > ========== file expression.ml > > type expression = > | Abstraction of (string * types) list * expression > .... > | Formula of formula > ========== file formula.ml > > type formula = > | Forall of (string * types) list * formula > ... > | Expression of expression You can't. Instead, create a single interface (.mli) file containing all the type definitions. No ml file is required. Note that you must define class _types_ not classes. Your actual classes should be defined and constrained to these types, and client modules should only know the class types (not the classes). This way, indirection (abstraction) is used to solve the problem. > It would be great if one could incorporate a class into the > recursion. But I guess as a first step one has to allow recursion > between classes and types in one module as in > > type t = .... > and class c = ... > and type t' = ... See previous post: you can do this now, by first abstracting the classes over the types: class type c' ['t] = ... type t = .... t c' ... class type c = t c' Again, indirection (abstraction) is used to solve the problem. It is slightly more effort to first give (otherwise useless) generic class types, then instantiate them. Considerably more effort is required to give a class type, and then separately an implementation (since a whole lot of method signatures need to be repeated). -- 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