I keep looking for a new OCaml project. It hits a lot of sweet spots that are not matched by other languages: idiomatic functional programming, static types, powerful compiler, [syntax extensions](http://caml.inria.fr/pub/old_caml_site/camlp4/index.html), and the language's mindset allows for stateful solutions to problems when these are the most natural. Throughout this post I will use the running example of evaluating an abstract syntax tree for an imperative language. Once a file has been lexed and parsed, the structure that you are left with is an *abstract syntax tree*, an internal data structure that encompasses what your program semantically means. Evaluating an imperative language like JavaScript, Java, C, C++, etc involves separating out: * *expressions* that evaluate to a value: `1 + 1`, `ptr->field`. * *statements* that change state or transfer control: `a = 1`, `if (!ptr) { log_error(); }`. Statements contain expressions: right-hand-side of the assignment `a = 1` is a integer literal. JavaScript contains first class functions: ```javascript var a = function (i) { // anonymous function return i * 2; } ``` The enclosing `function` is an expression (a value that can be assigned and passed as an argument to another function). The body of a function is a set...
|
|
Scooped by
Srdjan Strbanovic
onto Functional programming December 19, 2014 9:47 AM
|
No comment yet.
Sign up to comment
Your new post is loading...