Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you're looking for is the '<em>Derived arrays</em>' section in the Data.Array documentation: <a href="http://hackage.haskell.org/packages/archive/array/latest/doc/html/Data-Array.html#5" rel="noreferrer">http://hackage.haskell.org/packages/archive/array/latest/doc/html/Data-Array.html#5</a> which houses the function:</p> <blockquote> <p><strong>ixmap</strong> :: (Ix i, Ix j) => (i, i) -> (i -> j) -> Array j e -> Array i e</p> <p>ixmap allows for transformations on array indices. It may be thought of as providing function composition on the right with the mapping that the original array embodies.</p> <p>A similar transformation of array values may be achieved using fmap from the Array instance > of the Functor class.</p> </blockquote> <p>The following code:</p> <pre><code>ixmap newBounds trans backingArray </code></pre> <p>would return an array with bounds <code>newBounds</code>, and when indexed with <code>!i</code>, the <em>index transformation function</em> is applied onto the index <code>i</code> before being used to index <code>backingArray</code>.</p> <hr> <p><strong>Example</strong> if you had the array "Hello World" (helloWorldArray below) and you want to only see "ell" as a derived <em>zero-based</em> (sub-)array:</p> <pre><code>&gt; let helloWorldArray = listArray (0,length str - 1) str -- 0-based array where str = "Hello World" &gt; let ellArray = ixmap (0,2) succ helloWorldArray -- also 0-based array &gt; ellArray ! 0 'e' &gt; ellArray ! 1 'l' &gt; ellArray ! 2 'l' </code></pre> <p>Here we say that our new array <code>ellArray</code> has indices from <code>0</code> through <code>2</code>. Our index transformation is simply to add one (<code>succ</code>), because we want to map the index range <code>[0..2]</code> to <code>[1..3]</code> in the original <code>helloWorldArray</code>.</p> <p>Of course, <code>ixmap</code> is abstract enough to capture any index transformations: even as to view 2 dimensional arrays as 1 dimensional arrays and vice-versa. It's better to think of it as creating a 'view' onto array data <em>rather</em> than a 'sub-array' function.</p> <p>For more examples you can look here: <a href="http://zvon.org/other/haskell/Outputarray/ixmap_f.html" rel="noreferrer">http://zvon.org/other/haskell/Outputarray/ixmap_f.html</a></p>
    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.
    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