Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>timesToUnixTimes :: [String] -&gt; [UTCTime] </code></pre> <p>As ja points out, this is not a simple <code>map</code>. But the final step of converting a <code>[Integer]</code> to a <code>[UTCTime]</code> is a <code>map</code>:</p> <pre><code>timesToUnixTimes (s : ss) = map psUTC (i : is) where </code></pre> <p>The first element of the input list, <code>s</code>, had better be a unixtime:</p> <pre><code> i = read (tail s) :: Integer </code></pre> <p>Subsequent elements, <code>ss</code>, may be either, so the decoding function needs access to the previous element of the output list:</p> <pre><code> is = zipWith timeToInteger ss (i : is) </code></pre> <p>Writing <code>timeToInteger :: String -&gt; Integer -&gt; Integer</code> is left as an exercise.</p> <p>Two points from this:</p> <ol> <li><p>You can think of <code>zipWith</code> as mapping a function over two lists at a time (similarly, <code>zipWith3</code> maps a function over three lists at a time, <code>zipWith4</code> maps over four lists at a time, etc; there isn't a function called <code>zipWith1</code> because it's called <code>map</code>).</p></li> <li><p><code>is</code> appears in its own definition. This works thanks to <s>laziness</s> non-strictness.</p> <ol> <li>The first element of <code>is</code> depends on the first element of <code>ss</code> and on <code>i</code>.</li> <li>The second element of <code>is</code> depends on the second element of <code>ss</code> and on the first element of <code>is</code>.</li> <li>The third element of <code>is</code> depends on the third element of <code>ss</code> and on the second element of <code>is</code>.</li> <li>Etc.</li> </ol> <p>No element of <code>is</code> depends on itself, or on a later element of <code>is</code>.</p></li> </ol>
 

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