Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
array
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Glasgow Haskell Compiler
Packages
array
Commits
0b6a11a5
Commit
0b6a11a5
authored
2 years ago
by
meooow
Committed by
Lei Zhu
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add Data.MArray.{modifyArray,modifyArray'}
parent
4053f7cf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!18
Add Data.MArray.{modifyArray,modifyArray'}
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Data/Array/Base.hs
+25
-0
25 additions, 0 deletions
Data/Array/Base.hs
Data/Array/MArray.hs
+2
-0
2 additions, 0 deletions
Data/Array/MArray.hs
changelog.md
+4
-0
4 additions, 0 deletions
changelog.md
with
31 additions
and
0 deletions
Data/Array/Base.hs
+
25
−
0
View file @
0b6a11a5
...
...
@@ -922,6 +922,31 @@ writeArray marr i e = do
n
<-
getNumElements
marr
unsafeWrite
marr
(
safeIndex
(
l
,
u
)
n
i
)
e
{-# INLINE modifyArray #-}
-- | Modify an element in a mutable array
--
-- @since FIXME
modifyArray
::
(
MArray
a
e
m
,
Ix
i
)
=>
a
i
e
->
i
->
(
e
->
e
)
->
m
()
modifyArray
marr
i
f
=
do
(
l
,
u
)
<-
getBounds
marr
n
<-
getNumElements
marr
let
idx
=
safeIndex
(
l
,
u
)
n
i
x
<-
unsafeRead
marr
idx
unsafeWrite
marr
idx
(
f
x
)
{-# INLINE modifyArray' #-}
-- | Modify an element in a mutable array. Strict in the written element.
--
-- @since FIXME
modifyArray'
::
(
MArray
a
e
m
,
Ix
i
)
=>
a
i
e
->
i
->
(
e
->
e
)
->
m
()
modifyArray'
marr
i
f
=
do
(
l
,
u
)
<-
getBounds
marr
n
<-
getNumElements
marr
let
idx
=
safeIndex
(
l
,
u
)
n
i
x
<-
unsafeRead
marr
idx
let
!
x'
=
f
x
unsafeWrite
marr
idx
x'
{-# INLINE getElems #-}
-- | Return a list of all the elements of a mutable array
getElems
::
(
MArray
a
e
m
,
Ix
i
)
=>
a
i
e
->
m
[
e
]
...
...
This diff is collapsed.
Click to expand it.
Data/Array/MArray.hs
+
2
−
0
View file @
0b6a11a5
...
...
@@ -31,6 +31,8 @@ module Data.Array.MArray (
-- * Reading and writing mutable arrays
readArray
,
-- :: (MArray a e m, Ix i) => a i e -> i -> m e
writeArray
,
-- :: (MArray a e m, Ix i) => a i e -> i -> e -> m ()
modifyArray
,
modifyArray'
,
-- * Derived arrays
mapArray
,
-- :: (MArray a e' m, MArray a e m, Ix i) => (e' -> e) -> a i e' -> m (a i e)
...
...
This diff is collapsed.
Click to expand it.
changelog.md
+
4
−
0
View file @
0b6a11a5
...
...
@@ -9,6 +9,10 @@
*
Add
`Data.Array.IArray.(!?)`
*
Add
`Data.Array.MArray.modifyArray`
and
`Data.Array.MArray.modifyArray'`
.
These are also exposed from
`Data.Array.IO`
,
`Data.Array.ST`
, and
`Data.Array.Storable`
.
## 0.5.5.0 *February 2022*
*
Compatibility with GHC's new JavaScript backend.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment