arr // [(idx,newvalue)]
(//) is a function that takes an array and a list of pairs of indexes and values and returns an array with those indexes set to those values.
(//) is a function that takes an array and a list of pairs of indexes and values and returns an array with those indexes set to those values.
Prelude> let x = [1, 2, 3]
Prelude> x
[1,2,3]
Prelude> x // [(2,42)]
<interactive>:5:3:
Not in scope: `//'
Perhaps you meant one of these:
`/' (imported from Prelude), `/=' (imported from Prelude)
So, how canonical is this if it's not in Prelude?This makes it a little harder to get started but considering the kinds of things programmers put up with on a daily basis is extremely mild.
Data.Array and // are also described in the Haskell 2010 report
https://www.haskell.org/onlinereport/haskell2010/haskellch14...
λ :m Data.Array
λ let x = array (1,3) [(1,1), (2,2), (3,3)]
x :: (Num e, Num i, Ix i) => Array i e
λ x
array (1,3) [(1,1),(2,2),(3,3)]
it :: (Ix i, Num i, Num e) => Array i e
λ x // [(2,42)]
array (1,3) [(1,1),(2,42),(3,3)]
it :: (Num i, Num e, Ix i) => Array i e
λ x
array (1,3) [(1,1),(2,2),(3,3)]
it :: (Ix i, Num i, Num e) => Array i e
Note however that this isn't mutating x directly, to do mutation would require state or a monad.What's wrong with something like "set arr idx newvalue"?
Nothing. See here: https://news.ycombinator.com/item?id=15017853
It's called "writeArray".