Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] Polymorphic functors / modules and OCaml-R

8 views
Skip to first unread message

Guillaume Yziquel

unread,
Nov 16, 2009, 2:34:20 AM11/16/09
to caml...@inria.fr
Hello.

I've been trying stuff like these:

> # module type 'a A = sig
> Error: Parse error: [a_UIDENT] expected after "type" (in [str_item])
> # module type ['a] A = sig
> Error: Parse error: [a_UIDENT] expected after "type" (in [str_item])
> # module type A = sig module type B end
> ;;
> Error: Failure: "abstract/nil module type not allowed here"
> #

Is there a way, somehow, of introducing such polymorphism in modules /
functors?

That would help me a lot. I'm currently try to write bindings for R
code, with OCaml-R, and I can come up with stuff like this:

> module Description : R.LibraryDescription = struct
> let name = "xts"
> let symbols = ["xts"]
> end
>
> module Library : R.Library = OCamlR.Require (Description)
>
> let [xts] = Library.root

What would be nice would be Description to be polymorphic in some sense
or another, so that I could describe the various R symbols that are made
available by the xts library.

The other, rather unrelated solution I see would be to replace stuff
above by something like:

> module Description : R.LibraryDescription = struct
> let name = "xts"
> let symbols = ["xts"; "print_xts"]
> end
> module Library : R.Library = OCamlR.Require (Description)
>
> type t
> external list_to_tuple : 'a list -> 'b = "list_to_tuple"
> let ( (xts : unit -> t),
> (print_xts : t -> unit)
> ) = list_to_tuple Library.root

where list_to_tuple would be a function constructing the tuple (no fixed
size) representing a given list. This is rather unsafe...

A polymorphic module, with argument a module type, would be something
very useful to describe a R library...

All the best,

--
Guillaume Yziquel
http://yziquel.homelinux.org/

_______________________________________________
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

Goswin von Brederlow

unread,
Nov 16, 2009, 3:12:27 AM11/16/09
to guillaum...@citycable.ch, caml...@inria.fr
Guillaume Yziquel <guillaum...@citycable.ch> writes:

> Hello.
>
> I've been trying stuff like these:
>
>> # module type 'a A = sig
>> Error: Parse error: [a_UIDENT] expected after "type" (in [str_item])
>> # module type ['a] A = sig
>> Error: Parse error: [a_UIDENT] expected after "type" (in [str_item])
>> # module type A = sig module type B end
>> ;;
>> Error: Failure: "abstract/nil module type not allowed here"
>> #
>
> Is there a way, somehow, of introducing such polymorphism in modules /
> functors?

Isn't that exactly what a functor is? You just need to wrape the 'a type
in a module.

MfG
Goswin

0 new messages