caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* circular types?
@ 2000-10-20  2:35 Chris Hecker
  2000-10-20 12:24 ` Pierre Weis
  0 siblings, 1 reply; 21+ messages in thread
From: Chris Hecker @ 2000-10-20  2:35 UTC (permalink / raw)
  To: caml-list


How do I do this:

type foo = B of bar
type bar = F of foo

That is, I want two types to refer to each other.  I thought putting a 

type bar

above foo would do it, but that's an abstract type now, and when I redefine it I get a different type?

Chris



^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: circular types?
@ 2000-10-23  7:43 Tom Hirschowitz
  2000-10-23 15:35 ` Brian Rogoff
  2000-10-24  8:37 ` Hendrik Tews
  0 siblings, 2 replies; 21+ messages in thread
From: Tom Hirschowitz @ 2000-10-23  7:43 UTC (permalink / raw)
  To: caml-list

> Nope, no forwards in Ocaml. At some point, you'll have to tie the recursive 
> knot with an "and". If the problem you're having is that "far away" means 
> "in different modules" then you bump into the lack of recursive modules, 
> IMO the biggest PITA with ML style modules.

Hi, 

I'm pleased to see I'm not working for nobody. 
Actually I'm not working exactly on recursive modules, but rather on 
mixin modules.
Instead of defining your two modules and then link them, you would 
create a new one with the holes filled.
For instance, for Brain's example, you would write something like : 

mixin A = 
  mix 
    deferred module CompositeSet : sig type t ... end
    type composite = { data : string ; children : CompositeSet.t }
  end;;

mixin B = 
  mix
    deferred type composite
    module CompositeSet = 
      struct
        type t = C of composite | D
      end
  end

mixin C = A + B

In fact, this one is too difficult for me right now, because it 
relies on a mutual dependency between a type and a module.
Since I'm just beginning this, I would really be pleased by any 
comments, suggestions or questions about it.

Ciao.

Tom




^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: circular types?
@ 2000-10-24  8:48 Tom Hirschowitz
  2000-10-26  8:39 ` Hendrik Tews
  0 siblings, 1 reply; 21+ messages in thread
From: Tom Hirschowitz @ 2000-10-24  8:48 UTC (permalink / raw)
  To: caml-list

Hendrik Tews writes :
I would like to have recursive types spread over different files
like ....

That should be possible, but again there will be a mixing step, 
creating
a new module, in which the different parts of your recursive types 
block
are linking together.

In your example, you would have :


========== file types.ml

? type formula

type types =
  | Product of types list
  ...
  | Comprehension of formula

===================================

========== file expression.ml

? type formula

type expression =
  | Abstraction of (string * types) list * expression
  ....
  | Formula of formula

===================================

========== file formula.ml

? type expression

type formula = 
  | Forall of (string * types) list * formula
  ...
  | Expression of expression

===================================

========== file next.ml

module MyTypes = Types + Expression + Formula;;

...

===================================

Is it enough?


> 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' = ...

I'm not here until now, since in the prototype, there are only 
recursive values. But probably O-people at Cristal could answer this 
point.

Bye,

Tom






^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2000-10-26 18:38 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-20  2:35 circular types? Chris Hecker
2000-10-20 12:24 ` Pierre Weis
2000-10-20 21:34   ` Chris Hecker
2000-10-21  8:02     ` Pierre Weis
2000-10-21 18:37       ` Chris Hecker
2000-10-21 12:22     ` Vitaly Lugovsky
2000-10-21 18:29       ` Chris Hecker
2000-10-21 22:36     ` Brian Rogoff
2000-10-23 18:43     ` Anton Moscal
2000-10-23  7:43 Tom Hirschowitz
2000-10-23 15:35 ` Brian Rogoff
2000-10-25 14:03   ` John Max Skaller
2000-10-25 19:47     ` Brian Rogoff
2000-10-26  9:12     ` Hendrik Tews
2000-10-26 16:37       ` John Max Skaller
2000-10-24  8:37 ` Hendrik Tews
2000-10-25 14:31   ` John Max Skaller
2000-10-26  8:51     ` Hendrik Tews
2000-10-24  8:48 Tom Hirschowitz
2000-10-26  8:39 ` Hendrik Tews
2000-10-26  9:11   ` Tom Hirschowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).