Browse thread
Private types in 3.11, again
[
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: | Dario Teixeira <darioteixeira@y...> |
| Subject: | Re: [Caml-list] Private types in 3.11, again |
Hi,
> So my question is how can I make the Foobar code behave as if it were
> defined inside Node. Based on a previous thread [1], I'm guessing there
> is a solution, but I've been unable to hit on its exact formulation.
There have been no replies yet to my question, but I'm still stuck with
this little problem. The offending code is below; though it doesn't
compile, I reckon that all it needs is a suitable type annotation. I'm
guessing this because the function capitalise_node function will compile
fine if placed inside the Node module. Any ideas on how to solve this?
Thanks in advance!
Best regards,
Dario Teixeira
module Node:
sig
type node_t =
private
| Text of string
| Bold of node_t list
| Href of string
| Mref of string * node_t list
type +'a t = private node_t
val text: string -> [> `Nonlink ] t
val bold: 'a t list -> 'a t
val href: string -> [> `Link ] t
val mref: string -> [< `Nonlink ] t list -> [> `Link ] t
end =
struct
type node_t =
| Text of string
| Bold of node_t list
| Href of string
| Mref of string * node_t list
type +'a t = node_t
let text txt = Text txt
let bold seq = Bold seq
let href lnk = Href lnk
let mref lnk seq = Mref (lnk, seq)
end
module Foobar:
sig
open Node
val capitalise_node: 'a t -> 'a t
end =
struct
open Node
let capitalise_node node =
let rec capitalise_node_aux forbid_link node = match (forbid_link, node) with
| (_, Text txt) -> text (String.capitalize txt)
| (x, Bold seq) -> bold (List.map (capitalise_node_aux x) seq)
| (false, Href lnk) -> href lnk
| (false, Mref (lnk, seq)) -> mref lnk (List.map (capitalise_node_aux true) seq)
| _ -> failwith "oops"
in capitalise_node_aux false node
end