3 ms·
If I oversimplify I would say that due to pattern matching and functional nature of OCaml you can avoid much of the boilerplate code needed for building tree no
by edwintorok 11y ago
If I oversimplify I would say that due to pattern matching and functional nature of OCaml you can avoid
much of the boilerplate code needed for building tree nodes, or finding the node you want, allowing you to focus on the high-level task you want to actually achieve.
In fact one thing that you might notice in the beginning when reading OCaml is that the code seems more "dense".
In C I was used to reading code by skipping over large chunks of it (again I'm oversimplifying here) like the one below, and one of the things I had to get used to when learning OCaml was to slow down and avoid skipping large chunks of code:
if (some_complex_condition == failed) {
/* ... large block of code for error handling to ignore on first read .. */
}
result = malloc(...);
result->... = ...;
result->... = ....;
Here are some examples of what is possible with symbolic manipulation in OCaml, although I would recommend learning a bit of OCaml syntax and concepts from a book first
(such as Real World OCaml):
A short example of implementing regular expression matching using Antimirov's partial derivatives that illustrates symbolic manipulation:
http://semantic-domain.blogspot.ro/2013/11/antimirov-derivatives-for-regular.html http://semantic-domain.blogspot.ro/2013/11/antimirov-derivat...
A step-by-step explanation of a DSL optimizer that doesn't use too many advanced notions of OCaml:
http://okmij.org/ftp/tagless-final/course/optimizations.html http://okmij.org/ftp/tagless-final/course/optimizations.html
A nice example of symbolic manipulation is this counter-example generator for regular expression equivalence:
http://perso.ens-lyon.fr/damien.pous/symbolickat/ http://perso.ens-lyon.fr/damien.pous/symbolickat/