Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a number of problems here.</p> <p>First of all, the result of a list comprehension is a list, so you're calling <code>Data.Vector.map</code> on a list, which won't work. And the <code>x</code> inside the comprehension is a <code>Vector</code>, which is another type mismatch. Either use a list instead of a Vector (along with <code>Prelude.map</code>) or convert the list to a <code>Vector</code> (in which case you can't use a list comprehension).</p> <p>Secondly, ignoring the list/<code>Vector</code> problem, <code>[i !! 2 | i &lt;- x]</code> will give you a list containing only the elements at position 2 from each sub-list. Using your example, the comprehension would yield <code>["12", "34"]</code>. Then when you map <code>read</code> over it, you'll get <code>[12, 34]</code>, rather than the output you're shooting for.</p> <p>Finally, the output you're wanting to see is not valid for lists or for <code>Vectors</code> in Haskell. Both types of container must be homogeneous, i.e. they cannot contain values of more than one type. A <code>[Int]</code> cannot contain <code>String</code>s, nor can a <code>[String]</code> contain <code>Int</code>s, but your desired output contains both. There are ways you can get around this using existential types, but chances are there's a better solution for your underlying problem than to try to build heterogeneous collections.</p> <p>Edit: You edited the last part of your post to use tuples, so the above paragraph no longer applies. The first two problems I mentioned still exist, though.</p> <p>If you start with a list of 4-tuples (<code>[(String, String, String, String)]</code>), you can get what you want like this:</p> <pre><code>&gt; let x = [("a", "b", "12", "d"), ("e", "f", "34", "g")] &gt; map (\(a, b, c, d) -&gt; (a, b, read c :: Int, d)) x [("a", "b", 12, "d"), ("e", "f", 34, "g")] </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.
    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