Re:Purity in D
by Rickasaurus on Monday May 28, 2012 @05:30AM
(#4032632)
I was disappointed by the '›Weak‹ Purity Allows for Stronger Guarantees' section. I expected an explanation of why weak purity might give stronger guarantees, but what I got was a set of reasons why weak purity is more practical for a compiler that can't handle FP optimizations. Where's the stronger guarantees?
[ Parent
| on HN ]
When I read that section, it occurred to me that "weak purity" is like monads and "strong purity" is purity as we know it in the FP world. Then drawTriangle() become an action in some monad (I imagined a State one) and renderScene() is just a pure function using some monadic computations (doing something like evalState (drawTriangle ...)).
I don't know how to explain that without analogies to Haskell (which, I presume, author deliberately avoids), though.
Re:Purity in D
by klickverbot on Monday May 28, 2012 @06:14AM
(#4032738)
Yes, I deliberately tried to avoid using FP slang as to not scare away interested C++ programmers. This is also the reason why I referred to I/O »in the classical sense« instead of mentioning the m-word. ;)
Re:Purity in D
by klickverbot on Monday May 28, 2012 @05:37AM
(#4032656)
Referring to the toy example from the article: Without »weak« purity, renderScene() could not be pure at all, but now, it can even be »strongly« so.
The point is that it enables some function to be pure in the traditional sense even if their implementation relies on mutating data – any idea how I could make this more clear?