News for hackers. Stuff that matters.
Re:How do I modify a variable in Haskell? by Peaker on Tuesday August 15, 2017 @11:01AM (#15018830)
Doing this kind of effect sequencing in Haskell is annoying indeed. A radical library can mitigate that but that would be really unidiomatic.

Could be nice to have sugar like expr[!x] that expand to: x >>= \genName -> .. expr[genName] ..

So you could write: writeArr arr !(readArr ..) !(readArr ..)

Then if you add an operator to do the reading it becomes quite reasonable.

Re:How do I modify a variable in Haskell? by WarDaft on Friday August 18, 2017 @03:10PM (#15048932)
Well, you can add operators, though you almost certainly should think about more idiomatic solutions first, it's entirely possible to write operators to allow a statement like:

  arr .~ (i,j) .= arr ! (a,b) + arr ! (x,y)
You make orphan instances for Indexed and Num, and then .~ is just a slight tweak on the adjust function that Indexed provides and .= is literally a direct synonym for $ that just looks better in this context. This is actually more flexible than most languages, because now (arr .~ (i,j)) or (.~ (i,j)) can be named and applied to multiple things should that be desirable for some reason. Also note that this code is very weird, as arr is not an array, but an IO action describing how to produce one. Operations on it actually produce diffing instructions to be applied elsewhere. I have also not tested the performance.

These exact things are not in base because they are discouraged and not supposed to be easy. Note that the lens library provides operators more or less just like this for a wide variety of data types, in a safe and composable way.

Re:How do I modify a variable in Haskell? by Peaker on Sunday August 20, 2017 @08:10AM (#15058083)
Taking IO actions just to do the bind for the caller goes against the benefits you usually get from purity.
Re:How do I modify a variable in Haskell? by tome on Tuesday August 15, 2017 @12:14PM (#15019532)
OK, I know this isn't nice but it's already part of the way there

    writeArray arr (i,j) =<< ((+) <$> readArray arr (i,j-1) <*> readArray arr (i-1,j))
Re:How do I modify a variable in Haskell? by jstimpfle on Tuesday August 15, 2017 @05:31PM (#15022823)
This is not only not nice, it's just a bad idea. (and I understand it!)
Re:How do I modify a variable in Haskell? by tome on Wednesday August 16, 2017 @04:44AM (#15025912)
I think you may have misinterpreted my comment.