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

  • SEARCH
  • Home
  • 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 9127705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:20:40+00:00 2026-06-17T07:20:40+00:00

Is there a way how efficiently to construct a slice (a sub-array view) out

  • 0

Is there a way how efficiently to construct a slice (a sub-array view) out of an IOArray, or MArray in general? That is, taking the same array, just restricting the bounds. The signature could be

(MArray a e m, Ix i) => a i e -> i -> i -> m (a i e)

For example, taking an array with bounds (1,1000) and making a view that gives access only to elements with bounds (500,700) of the original array. I searched the documentation but I couldn’t find any such function.

  • 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-17T07:20:42+00:00Added an answer on June 17, 2026 at 7:20 am

    Given how the array types are implemented, this isn’t something that would really be a feature of an array, which is probably why nothing along these lines exists already.

    Recall that an array is a contiguous block of memory, so at some level every array with n elements has bounds (0, n-1). However, wanting indices other than integers starting from zero is common enough that Haskell provides a type class for defining arbitrary bounds and translating from an element inside those bounds to a 0-based integer index for the actual block of memory.

    This causes some difficulty for what you want to do because it’s assumed that the bounds for an array cover its entire range. So if you were to simply create a copy of an existing array that used the same memory chunk but different bounds, the indices would not line up–in your example, index 500 in the subarray would be the same as index 1 in the original array. Not helpful.

    The simplest approach here would be to define your own array type that wraps an existing array and stores any extra information needed to translate indices, so that it reports its own bounds as the smaller range, but looks things up in the wrapped array based on the full range. You can then use the wrapped array type everywhere (and give it all the expected instances, &c.) with newly-created arrays simply using the same bounds as the “real” array. You can perform whatever translations you need on the indices here, so this approach should generalize to index types that don’t have a linear order as well (e.g., “multi-dimensional” arrays indexed by tuples).

    You could probably also do something involving a wrapper around your index type and giving the wrapper version a weird Ix instance that translated things automatically somehow, which would let you use the existing array types. That would probably be trickier to make work correctly, though.

    I don’t think there’s any way to do it without changing either the array or index types.

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

Sidebar

Related Questions

Is there a way to compute efficiently the Fourier transform of the max of
Is there an efficient way to clone an object yet leave out specified properties?
I'm wondering if there's a super-efficient way of confirming that an Image object references
Is there a way to construct a new std::vector with uninitialized (non-zero) values or
Is there an efficient way to version store procedures written in PL/SQL? (I only
Is there a more efficient way to list files from a bucket in Amazon
Is there are more efficient way than the following for selecting the third parent?
Is there a fast/efficiency way to check if a table is empty? DECLARE @StartEndTimes
Is there any way we could do efficient paging with petapoco and mvc3. At
I'm curious if there is an efficient way to wait for the front page

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.