Accueil     À propos     Téléchargement     Ressources     Contactez-nous

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

[Caml-list] extensible records again
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2004-03-24 (10:05) From: Jacques Garrigue Subject: Re: [Caml-list] extensible records again
```From: Julien Signoles <Julien.Signoles@lri.fr>
> I think you don't use t0 in Y0 and Ysig because t0 is enclosed
> in XY. I would write somethink like:
>
> (* [...] *)
> module Y0(Xrec : Xrec) = struct
>   module XY = X0(Xrec)
>   type t = [XY.t | `C]
> end
> module type Ysig = sig
>   module XY : Xsig
>   type t = [ XY.t | `C]
> end
> module rec Y : (Ysig with module XY = X0(Y)) = Y0(Y)

Nicer. I didn't know that you could specify modules inside a signature
through functor application. Looks powerful.
This allows this even more modular encoding:

open Printf
module type Xt = sig type t end
module type Xrec = sig module T : Xt val show : T.t -> string end
module X0t (Xt : Xt) = struct type t = [`A of Xt.t | `B] end
module X0(Xrec : Xrec) =
struct
module T = X0t(Xrec.T)
let rec show = function
`A x -> "A" ^ Xrec.show x
| `B -> "B"
end
module rec X : (Xrec with module T = X0t(X.T)) = X0(X)
module Y0t(Xt : Xt) = struct type t = [X0t(Xt).t | `C] end
module Y0(Xrec : Xrec) =
struct
module T = Y0t(Xrec.T)
module XY = X0(Xrec)
let rec show = function
#XY.T.t as x -> XY.show x
| `C -> "C"
end
module rec Y : (Xrec with module T = Y0t(Y.T)) = Y0(Y)

Note of course that this is not very interesting on this simple
example. Using that many modules only gets useful if you have several
mutually recursive types.

Jacques Garrigue

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

```