Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As for the first one, it's a very basic way of recursion. However, it seems to be missing a part:</p> <pre><code>myLength [] = 0 </code></pre> <p>It works by scaling off one element at the time from the list and adding one to the result. To visualise, consider the call</p> <pre><code>myLength [1,2,3] </code></pre> <p>which will evaluate to:</p> <pre><code>1 + myLength [2,3] 1 + 1 + myLength [3] 1 + 1 + 1 + myLength [] 1 + 1 + 1 + 0 </code></pre> <p>which is 3.</p> <p>As for the second one, well, you have already split the string at the next line break into two parts: pre and suf. Now, suf will start with either a \n, or a \r, or a \r\n. We want to remove these. So we use pattern matching. See how the rest variable is essentially the suf variable minus the initial line break character(s).</p> <p>So we have pre, which is the first line, and rest, which is the rest of the text. So in order to continue splitting rest into lines we call splitLines on it recursively and concatenate the result to pre.</p> <p>To visualize, say you have the string "foo\nbar\r\nbaz".</p> <p>So, when calling, the result will be:</p> <pre><code>[ pre =&gt; foo, suf =&gt; \nbar\r\nbaz, rest =&gt; bar\r\n\baz ] foo : splitLines bar\r\nbaz </code></pre> <p>then splitLines is called again, and the result is expanded into:</p> <pre><code>[ pre =&gt; bar, suf =&gt; \r\nbaz, rest = baz ] foo : bar : splitLines baz </code></pre> <p>then once again:</p> <pre><code>[ pre =&gt; baz, suf =&gt; [], rest = [] ] foo : bar : baz </code></pre> <p>which is the final result.</p>
    singulars
    1. This table or related slice is empty.
    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