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 5974613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:58:02+00:00 2026-05-22T20:58:02+00:00

Imagine I want to map a function over an array, but the function has

  • 0

Imagine I want to map a function over an array, but the function has a type not just of
a -> b
but
a -> Int -> b
i.e. the function also takes an index. How do I do that?

  • 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-05-22T20:58:02+00:00Added an answer on May 22, 2026 at 8:58 pm

    Short answer, use traverse.

    Longer example:

    import qualified Data.Array.Repa as A
    import qualified Data.Vector.Unboxed as U
    
    arr1 :: A.Array A.DIM2 Double
    arr1 = A.fromVector (A.Z A.:. 2 A.:. 3) $ U.fromList [1::Double,2,3,4,5,6]
    
    arr2 :: A.Array A.DIM2 Double
    arr2 = A.traverse arr1 id (\lf i@(A.Z A.:. r A.:. c) -> 
                      (lf i) + (fromIntegral r) + (fromIntegral c))  
    

    arr1 is a 2×3 matrice. traverse is a function that takes (1) the original array, (2) a function for mapping source indices to target indices, and (3) a function that is given (i) a lookup function into the original array and (ii) an index that returns a new value.

    So here arr2 modifies each of the original elements by adding the row and column indices of that particular entry.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's imagine I want to make a templated function that returns the first element
Imagine that you want to develop a non-trivial end-user desktop (not web) application in
Imagine that I want to create an array from another array like this: $array
I want to create a helper method that I can imagine has a signature
Imagine a value, say '1234'. I want to map that value to an other
I succesfully generate my tile map and it works but when i want to
Imagine you want to animate some object on a WinForm. You setup a timer
Imagine I have String in C#: I Don’t see ya.. I want to remove
Imagine you have a classifieds website... When searching ads you want image thumbnails of
Imagine I have the folling XML file: <a>before<b>middle</b>after</a> I want to convert it into

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.