Hi,
I would like to know if there is any way to write a nested polymorphic
function instead of a polymorphic function.
The idea is that that the nested polymorphic function capture a some
values from the parent functions and takes generic arguments for
various needs.
Here is a very simple code but the idea is that I want to implement
some kind of "fold" function that reads tokens and call the user
function with "accumulator" and a value but the accumulator and result
should be polymorphic.
let rec read_richfile t =
...
let rec read_richtext f a =
match read_token t with
| StartElement "RichRegion" -> read_richtext (f a (RichBegin))
| EndElement "RichRegion" -> read_richtext (f a (RichEnd))
| StartElement "Color" -> read_richtext (f a (RichColor
(att_value_ "rgb")))
| EndElement "RichText" -> read_richtext (f a (RichEnd))
| _ -> read_richtext a
in read_richtext a
let other_fun () =
read_richtext (fun a b -> a :: b) []
let another_fun () =
read_richtext (print_rich_text richprinter) ()
Actually I am not very keen in writing a top-level function with all
necessary arguments each time I need to do some generic processing
that is specific to one master function.
Thanks,
Delphin
--
You received this message because you are subscribed to the Google Groups
"ocaml-developer" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/ocaml-developer?hl=en
For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html