Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think <em>sepp2k</em> already answered most of the question, but I'd like to add a couple of points that may clarify how F#/OCaml compiler interprets the code and explain some common uses. </p> <p><strong>Regarding the <code>'</code> symbol</strong> - this is just a part of a name (a valid identifier starts with a letter and then contains one or more letters, numbers or <code>'</code> symbols). It is usually used if you have a function or value that is very similar to some other, but is in some way <em>new</em> or <em>modified</em>.</p> <ul> <li><p>In your example, <code>xs</code> is a list that should be summed and the pattern matching decomposes the list and gives you a new list (without the first element) that you need to sum, so it is called <code>xs'</code></p></li> <li><p>Another frequent use is when declaring a local utility function that implements the functionality and takes an additional parameter (typically, when writing tail-recursive code):</p> <pre><code>let sum list = let rec sum' list res = match list with | [] -&gt; res | x::xs -&gt; sum' xs (res + x) sum' list 0 </code></pre></li> </ul> <p>However, I think there is usually a better name for the function/value, so I try to avoid using <code>'</code> when writing code (I think it isn't particularly readable and moreover, it doesn't colorize correctly on StackOverflow!)</p> <p><strong>Regarding the <code>::</code> symbol</strong> - as already mentioned, it is used to create lists from a single element and a list (<code>1::[2;3]</code> creates a list <code>[1;2;3]</code>). It is however worth noting that the symbol can be used in two different ways and it is also interpreted in two different ways by the compiler.</p> <p>When creating a list, you use it as an operator that constructs a list (just like when you use <code>+</code> to add two numbers). However, when you use it in the <code>match</code> construct, it is used as a <em>pattern</em>, which is a different syntactic category - the pattern is used to <em>decompose</em> the list into an element and the remainder and it succeeds for any non-empty list:</p> <pre><code>// operator let x = 0 let xs = [1;2;3] let list = x::xs // pattern match list with | y::ys -&gt; // ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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