caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] recursive types and modules problem
@ 2013-10-31 20:13 Nicolas Ojeda Bar
  2013-10-31 21:27 ` Wojciech Meyer
  2013-10-31 23:43 ` Jacques Garrigue
  0 siblings, 2 replies; 3+ messages in thread
From: Nicolas Ojeda Bar @ 2013-10-31 20:13 UTC (permalink / raw)
  To: caml-list

Dear list,

What is the best way to rewrite the following recursive definitions so that
I can actually compile them?

S = Set.Make (struct type t = t1 let compare x1 x2 = x1.stamp - x2.stamp end)

type t1 = {
  stamp : int;
  x : t2
}

and t2 = {
  y : S.t
}

Thank you very much!
Nicolas

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

* Re: [Caml-list] recursive types and modules problem
  2013-10-31 20:13 [Caml-list] recursive types and modules problem Nicolas Ojeda Bar
@ 2013-10-31 21:27 ` Wojciech Meyer
  2013-10-31 23:43 ` Jacques Garrigue
  1 sibling, 0 replies; 3+ messages in thread
From: Wojciech Meyer @ 2013-10-31 21:27 UTC (permalink / raw)
  To: Nicolas Ojeda Bar; +Cc: caml-list


Nicolas Ojeda Bar <N.Ojeda.Bar@dpmms.cam.ac.uk> writes:
> What is the best way to rewrite the following recursive definitions so that
> I can actually compile them?
>
> S = Set.Make (struct type t = t1 let compare x1 x2 = x1.stamp - x2.stamp end)
>
> type t1 = {
>   stamp : int;
>   x : t2
> }
>
> and t2 = {
>   y : S.t
> }

You just need to wrap it to recursive modules:

>>>>
module rec Foo : sig module Baz : sig type t1 end module S : sig type t end end  = struct

  module Baz = struct
    type t1 = {
      stamp : int;
      x : Bar.t2
    }
    type t = t1
 let compare x1 x2 = x1.stamp - x2.stamp  end

  module S = Set.Make(Baz)

end and Bar : sig type t2 end = struct

  type t2 = {
    y : Foo.S.t
  }

end
<<<<

--
Wojciech

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

* Re: [Caml-list] recursive types and modules problem
  2013-10-31 20:13 [Caml-list] recursive types and modules problem Nicolas Ojeda Bar
  2013-10-31 21:27 ` Wojciech Meyer
@ 2013-10-31 23:43 ` Jacques Garrigue
  1 sibling, 0 replies; 3+ messages in thread
From: Jacques Garrigue @ 2013-10-31 23:43 UTC (permalink / raw)
  To: Nicolas Ojeda Bar; +Cc: caml-list

2013/11/01 5:13、Nicolas Ojeda Bar <N.Ojeda.Bar@dpmms.cam.ac.uk> のメール:

> What is the best way to rewrite the following recursive definitions so that
> I can actually compile them?
> 
> S = Set.Make (struct type t = t1 let compare x1 x2 = x1.stamp - x2.stamp end)
> 
> type t1 = {
>  stamp : int;
>  x : t2
> }
> 
> and t2 = {
>  y : S.t
> }

A slightly shorter version, using the fact that recursive modules containing only
types require no implementation:

module rec T : sig
  type t1 = { stamp: int; x: t2 }
  and t2 = { y: S.t }
end = T
and S : Set.S with type elt = T.t1 =
  Set.Make
    (struct open T type t = t1 let compare x1 x2 = x1.stamp - x2.stamp end)

Jacques Garrigue


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

end of thread, other threads:[~2013-10-31 23:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-31 20:13 [Caml-list] recursive types and modules problem Nicolas Ojeda Bar
2013-10-31 21:27 ` Wojciech Meyer
2013-10-31 23:43 ` Jacques Garrigue

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