title: building a calculator with ocaml, no idea how to make sigma function
body: <p>I'm currently working on making a function that accepts self made type called exp and do arithmetic process (+-*/) and sigma. Current work status is as follows and I don't know how to proceed.</p>
  
  <pre><code>type exp = X
       | INT of int
       | ADD of exp * exp
       | SUB of exp * exp
       | MUL of exp * exp
       | DIV of exp * exp
       | SIGMA of exp * exp * exp
  
  let rec calculator : exp -&gt; int
  = fun e -&gt; match e with
  | INT x -&gt; x
  | ADD (e1, e2) -&gt; calculator e1 + calculator e2
  | SUB (e1, e2) -&gt; calculator e1 - calculator e2
  | MUL (e1, e2) -&gt; calculator e1 * calculator e2
  | DIV (e1, e2) -&gt; calculator e1 / calculator e2
  | SIGMA (e1, e2, e3) -&gt; let start = calculator e1 in 
                      let end = calculator e2 in
                      match start with
                      | x -&gt; 
                      | _ -&gt; expr2
  </code></pre>
  
  <p>for example, SIGMA (INT 1, INT 10, SUB(MUL(X,X), INT 1)) should produce result of 375.</p>
  
  <p>Actually I'm referencing a book called 'OCaml from the very beginning' and the reference code is also not working (below) so I cannot proceed right now...</p>
  
  <pre><code> type expr = 
   Num of int
  |Add of expr * expr
  |Subtract of expr * expr
  |Multiply of expr * expr
  |Divide of expr * expr
  
  let rec evaluate e = 
      match e with
      | Num x -&gt; x
      | Add (e, e') -&gt; evaluate e + evaluate e'
      | Subtract (e, e') -&gt; evaluate e - evaluate e'
      | Multiply (e, e') -&gt; evaluate e * evaluate e'
      | Divide (e, e') -&gt; evaluate e / evaluate e'
  </code></pre>