Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OCaml functions can be directly mapped to and from mathematical notation. However, you need to realize that mathematical notation is ambiguous. There is not a clear distinction between the value of the function, <code>f(i)</code>, on a particular value <code>i</code>, and the function <code>f</code> itself. Often one writes <code>f(i)</code> when one means the function <code>f</code> itself. ("Let us consider a function f(i)=i+1... This function is ...") To write correct code in OCaml, you have to see clearly whether you are working with a function itself or with the value of a function.</p> <p>When you say in mathematical notation, "Consider the function <code>f(i,j)=i+g(j) where g(j)=j</code>, you are writing the values of the functions. In OCaml, this is translated to</p> <pre><code> let f i j = let g j = j in i + g j;; </code></pre> <p>or</p> <pre><code> let f = let g = fun j -&gt; j in fun i j -&gt; i + g j;; </code></pre> <p>If you are trying to write <code>let sum = fun i -&gt; i + fun j -&gt; j;;</code>, then in mathematical notation you are saying "Consider the function <code>sum</code> such that <code>sum(i) = i + g</code>, where g is a function defined by <code>g(j)=j</code>." This is mathematically incorrect: you cannot add an <em>integer value</em> <code>i</code> and a <em>function</em> <code>g</code>. You can only add an integer <code>i</code> and the <em>value</em> of the function <code>g</code> on some other integer <code>j</code>. The expression "<code>i+g</code>" is undefined, strictly speaking. Either you wanted to write <code>i + g(i)</code>, or <code>i+g(j)</code>, but not <code>i+g</code>. This is so in mathematics, and this is so in OCaml.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload