LWN.net Logo

Semantic patching with Coccinelle

Semantic patching with Coccinelle

Posted Jan 22, 2009 16:18 UTC (Thu) by rwmj (guest, #5474)
In reply to: Semantic patching with Coccinelle by hppnq
Parent article: Semantic patching with Coccinelle

To prove your point, maybe you should write patches for Coccinelle so that it can produce semantic patches for OCaml?

OCaml actually supports the principle of semantic patching natively. You can perform almost arbitrary transformations of the abstract syntax tree at compile time, and this feature is used to implement interesting new features like Erlang-style bitstrings, type-safe access to databases, type-safe regular expressions, and much more.

Of course this is "strange" to many. (LISP programmers might recognise them as a very much more powerful version of LISP macros). But this is just one of the several ways that OCaml (and Haskell) are far beyond common programming languages.

Rich.


(Log in to post comments)

Semantic patching with Coccinelle

Posted Jan 22, 2009 16:28 UTC (Thu) by padator (guest, #56235) [Link]

> OCaml actually supports the principle of semantic patching natively.

This is not true. What you are talking about is different and is called
meta-programming. The need to refactor code is different. Even in OCaml
you often need to refactor code and there is no tool right now for OCaml
that does that. In fact we, in the coccinelle project, had in the past internally needed to refactor the coccinelle code and it was painful.

So I guess the comment of the other guy was right on the point; we decided to do
a semantic patching tool for C rather than a semantic patching tool for OCaml because there are more people writing C code :)

Semantic patching with Coccinelle

Posted Jan 23, 2009 0:42 UTC (Fri) by nix (subscriber, #2304) [Link]

Obviously, for symmetry, the thing to do is to write a semantic patching
tool (called, perhaps, ocamelle), in C, which carries out such
transformations on OCaml code. ;}

Semantic patching with Coccinelle

Posted Jan 23, 2009 5:38 UTC (Fri) by rwmj (guest, #5474) [Link]

I didn't mean that semantic patching was used in the same way as metaprogramming, but they are certainly analogous to each other. In one case, the transformed code is applied as a patch back on the source. In the other case, the transformed code is immediately passed to the compiler.

Anyhow .. for OCaml refactoring, Jane Street sponsored this project last summer. It's also something that Eclipse + the OCaml Eclipse plugin claims to do. I have not used either.

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds