Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7718875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:16:30+00:00 2026-06-01T03:16:30+00:00

I have a large nested vector that look like this: import Data.Vector let x

  • 0

I have a large nested vector that look like this:

import Data.Vector
let x = fromList [["a", "b", "12", "d"], ["e", "f", "34", "g"]...]

I would like to convert the strings to integers at position 2 in each nested list I was trying to do this with map and a comprehension like this:

let y = Data.Vector.map (\a -> read a :: Int) [i !! 2 | i <- x]

What am I doing wrong? I would like the output to be:

(("a", "b", 12, "d"), ("e", "f", 34, "g")...)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:16:31+00:00Added an answer on June 1, 2026 at 3:16 am

    There are a number of problems here.

    First of all, the result of a list comprehension is a list, so you’re calling Data.Vector.map on a list, which won’t work. And the x inside the comprehension is a Vector, which is another type mismatch. Either use a list instead of a Vector (along with Prelude.map) or convert the list to a Vector (in which case you can’t use a list comprehension).

    Secondly, ignoring the list/Vector problem, [i !! 2 | i <- x] will give you a list containing only the elements at position 2 from each sub-list. Using your example, the comprehension would yield ["12", "34"]. Then when you map read over it, you’ll get [12, 34], rather than the output you’re shooting for.

    Finally, the output you’re wanting to see is not valid for lists or for Vectors in Haskell. Both types of container must be homogeneous, i.e. they cannot contain values of more than one type. A [Int] cannot contain Strings, nor can a [String] contain Ints, 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.

    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.

    If you start with a list of 4-tuples ([(String, String, String, String)]), you can get what you want like this:

    > let x = [("a", "b", "12", "d"), ("e", "f", "34", "g")]
    > map (\(a, b, c, d) -> (a, b, read c :: Int, d)) x
    [("a", "b", 12, "d"), ("e", "f", 34, "g")]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large hash with nested arrays and hashes. I would like to
I have a large amount of nested data formatted in JSON . I would
I have a large list of objects inside JSON like this: var data =
I have large images displayed in a grouped tableview. I would like the images
I have a large nested array that I'm generating from parsing a CSV file
I have a large nested list that I am trying to animate using jquery
I have an object that consists primarily of a very large nested dictionary: class
I have a fairly large, three level deep, menu consisting of nested lists like
So I have a Python file that contains a large set of data of
I have a large nested that selects new classes, which works good, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.