Hacker Newsnew | comments | show | ask | jobs | submit login
Purity in D (klickverbot.at)
10 points by klickverbot 1070 days ago | 8 comments



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?

-----


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.

-----


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. ;)

-----


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?

-----


I am the author of the linked article – feedback and comments of any kind are very welcome!

-----


There is an issue with quotes — they appear to be swapped (tiny screenshot here: http://ompldr.org/vZHl4Mw). I made a little check, it's the same with every font you specified in your CSS, so the problem must lie within your blog generator or something.

-----


In German, guillemets are actually only used like that – contrary to, for example, French. I got in the habit of using them almost exclusively, and usually enter them explicitly (most non-Windows keyboard layouts have them in a convenient location). If this is confusing to non-German readers, though, I suppose I should reconsider their use.

-----


Oh, I didn't know that — thanks! But yes, to me it looked like I had some fonts wrong or something.

-----




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: