How do I modify a variable in Haskell?
isn&#x27;t the whole point that you write code completely differently in functional languages? rather than writing loop code to populate an array, you&#x27;d do something like the following (in JS as I&#x27;m not a haskell programmer):<p><pre><code>    const row = (len, onPositions) =&gt; {
        return (new Array(len)).map((item, index) =&gt; onPositions.includes(index) ? 1 : 0);
    };
    
    const matrixWithDiagonal = (len) =&gt; {
        return (new Array(len)).map((r, index) =&gt; row(len, [index]));
    }
</code></pre>
the point being, that the code generates the result directly, rather than making space for values and then looping through toggling the positions that should be set to on.<p>note: you wouldn&#x27;t really use the (new Array()) construct generally speaking (and it doesn&#x27;t work with .map anyway) but it&#x27;s easier than including underscore or ramda in the example.