Skip to content
Snippets Groups Projects

Add genArray

Merged Joachim Breitner requested to merge wip/joachim/genArray into master
4 unresolved threads

a quite useful function that I was missing when working with Data.Array recently.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
29 29 array, -- :: (Ix a) => (a,a) -> [(a,b)] -> Array a b
30 30 listArray, -- :: (Ix a) => (a,a) -> [b] -> Array a b
31 31 accumArray, -- :: (Ix a) => (b -> c -> b) -> b -> (a,a) -> [(a,c)] -> Array a b
32 genArray, -- :: (Ix a) => (a,a) -> (a -> b) -> Array a b
  • 193 193 listArray (l,u) es =
    194 194 let n = safeRangeSize (l,u)
    195 195 in unsafeArray (l,u) (zip [0 .. n - 1] es)
    196 --
  • Thanks for picking up this thread. Feel free to take over the MR, or close it and open a new one, as you see fit.

  • 193 193 listArray (l,u) es =
    194 194 let n = safeRangeSize (l,u)
    195 195 in unsafeArray (l,u) (zip [0 .. n - 1] es)
    196 --
    197 -- | Constructs an immutable array using a generator function.
    198 genArray :: (IArray a e, Ix i) => (i,i) -> (i -> e) -> a i e
    199 genArray (l,u) f = listArray (l,u) $ map f $ range (l,u)
    • If possible, I think the function should be called "generate", to match the API of the "vector" library which already has such a function. Choosing the same name here promotes consistency between the core libraries.

    • I see your point, but note that if you consider internal consistency to be more important to inter-package consistency, then the existing array generation functions array, listArray and accumArray suggest this naming. I don’t mind strongly either way.

    • Fair enough. Perhaps it was originally imagined that this module be imported unqualified, before we had Data.Vector, Data.Map, Data.Set etc. exporting clashing names. If you import it qualified, then e.g. Array.genArray becomes a bit redundant.

      I also don't have a strong opinion on this. I just wish to see the function added to the API.

    • Author Developer

      That’s my hypothesis as well. I think this code is rather old, and predates many current best practices :-)

    • Please register or sign in to reply
  • This is a very good addition to "array", to improve the ergonomics of using the library. I had already written up my own patch to add it, when I found this MR.

    What is the "export issue" that is preventing it from being merged? Is it something that we can fix?

  • Lei Zhu added 8 commits

    added 8 commits

    Compare with previous version

  • Maintainer

    What is the "export issue" that is preventing it from being merged?

    GHC.Arr doesn't have genArray, see commit !13 (8c9d5bd7)

  • Lei Zhu approved this merge request

    approved this merge request

  • merged

  • Please register or sign in to reply
    Loading