Re: [Caml-list] How to simplify an arithmetic expression ?

2011-10-02 Thread Gabriel Scherer
In my experience, the OCaml code doing recursive call and pattern matching is a relatively bad way to reason about such rewrite systems. Your questions are extremely pertinent, and relatively difficult to answer in general. For a start, I think your code indeed repeats useless traversals. This

Re: [Caml-list] How to simplify an arithmetic expression ?

2011-10-02 Thread Ernesto Posse
On Sun, Oct 2, 2011 at 1:51 PM, Diego Olivier Fernandez Pons dofp.oc...@gmail.com wrote:     OCaml list, It's easy to encapsulate a couple of arithmetic simplifications into a function that applies them bottom up to an expression represented as a tree let rec simplify = function     | Plus

Re: [Caml-list] ANN: lablgtk-react preview

2011-10-02 Thread Adrien
I forgot to mention that you need lablgtk2's adrien/mix branch for the examples (and only for the examples iirc). There are two reasons. It uses some additional API, especially #as_something methods and notify::foo signals. lablwebkit also requires a bug fix that it not merged into master yet.

Re: [Caml-list] How to simplify an arithmetic expression ?

2011-10-02 Thread Xavier Leroy
On Sun, Oct 2, 2011 at 10:08 AM, Gabriel Scherer wrote: One approach I like for such simplifications is the normalization by evaluation approach. NBE is neat, but I'm skeptical that it will work out of the box here: if you apply NBE to a standard evaluator for arithmetic expressions, it's not

Re: [Caml-list] How to simplify an arithmetic expression ?

2011-10-02 Thread Gabriel Scherer
Below is a quick tentative implementation of NbE, on a slightly restricted expression type (I removed the not-so-interesting Minus nodes). Sorry, I forgot to give a small example of what the implementation does. Really the obvious thing, but it may not be so obvious just looking at the code.