On Thu, Sep 10, 2009 at 9:14 PM, Guillaume Yziquel <[email protected]> wrote: > I'm not really familiar with syntax extensions. Can this 'polymorphic' > keyword be implemented with a syntax extension?
No, it can't. If you're talking about camlp4 syntax extensions, they're converted to regular OCaml programs at camlp4-time, wich is *before* the compiler see the program. It thus can't access any type information : you can have syntax extensions that send type information to the typer, but not the other way around : only purely syntaxic transformations are expressible. With a camlp4 extension, you could inspect the (syntaxically explicit) parameters of you method, and (syntaxically) generate a polymorphic type for each one : "polymorphic method foo bar baz = ..." would be translated into "method foo : 'a 'b . 'a -> 'b -> 'c = fun (bar : 'a) (baz : 'b) -> ...". This is probably not what you want. You could further enrich your extension with a "param" keyword that would not generate polymorphic types for some of the parameters "method foo bar (param baz) = ..", or have the "poly" keyword be parameter-specific "method foo (poly bar) baz = ...", but my general advice is not to try to much to do type-level transformation by syntaxic transformations : they tend to get flawed in ways you don't expect, and this is just not the right tool for the job. _______________________________________________ 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
