News for hackers. Stuff that matters.
Re:Are Monads a Waste of Time? by jordigh on Tuesday February 20, 2018 @07:45AM (#16419901)
I really like D's approach instead. A function declared pure can have no side effects but it can do whatever kind of mess it wants within its own code. It can have loops, assignments, reassignments, memory allocations, but it can't mutate variables outside its scope nor can it call any impure functions. I find this is a very practical compromise that lets you have the good parts of purity without ever getting the urge to write a blog post about monads.

https://dlang.org/spec/function.html#pure-functions

Re:Are Monads a Waste of Time? by quchen on Tuesday February 20, 2018 @08:33AM (#16420147)
Haskell has the ST type for this, which is a stripped version of IO in which we can still make proper mutable inplace updates like in other languages, but there is a »runner« function called »runST«, which guarantees that the computation it contains does not leak any state to the outside – in other words, »runST <impure>« is pure from the outside. This allows embedding of mutable algorithms, e.g. inplace sorting of vectors, into pure code.
Re:Are Monads a Waste of Time? by tome on Tuesday February 20, 2018 @08:28AM (#16420121)
That's what Haskell calls "ST" and is far less powerful than the general notion of monads.
Re:Are Monads a Waste of Time? by olavk on Tuesday February 20, 2018 @08:24AM (#16420092)
This is definitely cool, but monads is a more general concept. It can be used to isolate side-effects, but can also be used for many other things.
Re:Are Monads a Waste of Time? by gowld on Wednesday February 21, 2018 @02:05AM (#16427490)
This is "const" in c++
Re:Are Monads a Waste of Time? by jordigh on Wednesday February 21, 2018 @10:05AM (#16429916)
I don't think this is the same. My C++ is getting rusty, so correct me if I'm wrong, but making a function const is mostly about making the "this" pointer const. A const function can still mutate global variables or call non-const functions, such as operator<< on cout. A pure D function can do neither of those things.
Re:Are Monads a Waste of Time? by gowld on Wednesday February 28, 2018 @08:08PM (#16488843)
That's fair. C++ has const methods on objects, but I think nothing at global scope. But you shouldn't have global mutable state :-)