caml-list  

Re: [Caml-list] Private types in 3.11, again

Dario Teixeira
Mon, 19 Jan 2009 07:09:25 -0800

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






_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs