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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:41:26+00:00 2026-06-11T02:41:26+00:00

Data.Array doesn’t provide folds for the Array type. In Real World Haskell (ch. 12),

  • 0

Data.Array doesn’t provide folds for the Array type.

In Real World Haskell (ch. 12), the reason is said to be that Arrays could be folded in different ways based on the programmer’s needs:

First of all, there are several kinds of folds that make sense. We might still want to fold over single elements, but we now have the possibility of folding over rows or columns, too. On top of this, for element-at-a-time folding, there are no longer just two sequences for traversal.

Isn’t this exactly true of Lists? It’s very common to represent e.g. a matrix with a multidimensional List, but there are still folds defined for one-dimensional Lists.

What’s the subtlety I’m missing? Is it that a multidimensional Array is sufficiently different from an Array of Arrays?

Edit: Hm, even multidimensional arrays do have folds defined, in the form of instances of Data.Foldable.[0] So how does that fit in with the Real World Haskell quote?

[0] http://hackage.haskell.org/packages/archive/base/4.6.0.0/doc/html/Data-Foldable.html

  • 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-11T02:41:27+00:00Added an answer on June 11, 2026 at 2:41 am

    Since you mention the difference between a “multidimensional” Array and an Array of Arrays, that will illustrate the point nicely, alongside a comparison with lists.

    A fold (in the Foldable class sense) is an inherently linear operation, just as lists are an inherently linear structure; a right fold fully characterizes a list by matching its constructors one-for-one with the arguments to foldr. While you can define functions like foldl as well, there’s a clear choice of a standard, canonical fold.

    Array has no such transparent structure that can be matched one-for-one in a fold. It’s an abstract type, with access to individual elements provided by index values, which can be of any type that has an Ix instance. So not only is there no single obvious choice for implementing a fold, there also is no intrinsic linear structure. It does so happen that Ix lets you enumerate a range of indices, but this is more an implementation detail than anything else.

    What about multidimensional Arrays? They don’t really exist, as such. Ix defines instances for tuples of types that are also instances, and if you want to think of such tuples as an index type for a “multidimensional” Array, go ahead! But they’re still just tuples. Obviously, Ix puts some linear order on those tuples, but what is it? Can you find anything in the documentation that tells you?

    So, I think we can safely say that folding a multidimensional Array using the order defined by Ix is unwise unless you don’t really care what order you get the elements in.

    For an Array of Arrays, on the other hand, there’s only one sensible way to combine them, much like nested lists: fold each inner Array separately according to their own order of elements, then fold the result of each according to the outer Array‘s order of elements.


    Now, you might reasonably object that since there’s no type distinction between one-dimensional and multidimensional Arrays, and the former can be assumed to have a sensible fold ordering based on the Ix instance, why not just use that ordering by default? There’s already a function that returns the elements of an Array in a list, after all.

    As it turns out, the library itself would agree with you, because that’s exactly what the Foldable instance does.

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

Sidebar

Related Questions

postgres has an array data type, in this case a numeric array: CREATE TABLE
I have a table that displays data from a single array and organizes the
Why does this code always return 0? var possibleMatches = new Array(); $.getJSON('getInformation.php', function(data)
I'm loading JSON data (array of objects) via service, onReady, and want to display
I have some array data returned from an ajax call consisting of an image
How to get array data from json in c#? Here is the ajax code
I have this array Array ( [data] => Array ( [0] => Array (
I'm saving my data with Array, look: Get data: $data['address'] = $this->input->post('address'); Save: $this->load->model('mymodel');
How can I get the array data from a JSON sent back by my
i wish to send some data as array from my iphone app to server

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.