4 ms·
I like the article as a roundup of some ways in which programming is usually done in a non-pure way. However, this early quote is an example of why I disagree w
by Smaug123 10y ago
I like the article as a roundup of some ways in which programming is usually done in a non-pure way. However, this early quote is an example of why I disagree with the article:
"The slightest implicit imperative effect erases all the benefits of purity, just as a single bacterium can infect a sterile wound."
This is just not true. It's a fair rule of thumb that the more pure a function is, the easier it is to reason about its behaviour in a larger program.
If the article had stuck to a survey of common non-pure programming style and its pitfalls, I'd be much happier, but then it started on the "Informal Introduction to Monads", a topic which requires more ink and motivation than it was given here.
- catnaroek 10y agoThe type structure of call-by-value languages is inherently monadic. The monad in question is the identity functor iff the language is pure and terminating. Given the predominance of call-by-value languages, I'd expect every programmer to have a modicum of understanding of monads, if only to have the faintest idea how popular languages (yes, popular languages, not Haskell) work.
- Smaug123 10y agoBut I argue that this is not the place to do it (since it requires more ink and motivation than there is space left in the article). Anyway, you might as well say that every programmer should have a modicum of understanding of chip design, since every language is run on chips; but while it may make one a better programmer, it's not necessary in many higher-level languages.
- Smaug123 10y agoBy the way, it's very early on the morning after Christmas Day for me, so I'm struggling to load the structures into my mind properly. What category is the functor going from and to? The Precise Monadicity Theorem states that a functor G is monadic iff it has a left adjoint and it creates coequalizers of G-split pairs; what is the left adjoint of this functor? What does a coequalizer look like in the category? (I suspect I can work these out myself given a good statement of what the category is.)
- catnaroek 10y agoIf I understand correctly, the category in question can be characterized as follows: (0) For every type X in the language, there is an object X of values (not arbitrary terms!) of that type. (1) For every type X in the language, there is an object TX of closed programs (containing no free variables) of type X. T is the monad in question. (2) A morphism “f : X -> TY” is an arbitrary program of type Y containing a single free variable of type X. (3) (This is the part where I'm the least sure!) A morphism “f : X -> Y” is a pure terminating program containing a single free variable of type X. Also, I should've been more careful. If the language is pure and terminating, the monad in question is an equivalence of the category in question with itself. Not necessarily the identity functor.
- Roboprog 10y agoHoly crap. This. To paraphrase: "English, mofo. Do you speak it?!?" :-) I have been programming for over 30 years (which I suppose means nothing if it's just doing the same year over 30 times, but bear with me). Every other language (at the risk of being largely self selected, I know) I have ever worked on seems to incrementally add things or shift ideas around a little bit. Some communities might try to helpfully explain things to newcomers. But the perception of the Haskell community is that they revel in being as cryptic as possible in their purity. I'm not even sure if the above comment was serious (it was probably deadly serious), or absolute troll fodder nonsense. I know (more or less???) what a functor is, and I know what IFF means. Unfortunately, most of what I remember from mathematics comes down to a function has a domain of inputs and a range of outputs, and being a function implies you can predict the output from the input; a "type" is a rule for describing a set, possibly infinite (not much use for computing), of values; values can be "scalar", or multidimensional such as a vector/matrix/tensor. I know that "category" means something very specific to you guys, but not what. You lost me.
- Smaug123 10y agoIt was intended seriously, as a question between mathematicians, though I realise the language looks pretty intimidating :)
- 10y ago
- mpweiher 10y ago> It's a fair rule of thumb that the more pure a function is, > the easier it is to reason about its behaviour in a larger program. Yes, but there are a LOT of other factors that contribute to reasoning about functions (or methods). Though purity helps, naming (intension revealing selector) is actually more important, at least to me, and function chaining with unnamed intermediary results actually reduces readability significantly (though it seems cool).
- smoothdeveloper 10y ago> and function chaining with unnamed intermediary results actually reduces readability significantly For me this is the reverse, having assignment (to verbose and often redundant named identifers) interrupting the flow adds a lot of visual noise compared to an expression using chaining functions (using say |> operator in F#).
- marcosdumay 10y agoI'll agree with the article here. In a mixed setting, it is very hard to estimate how pure a function is. There are all kinds of interactions that you don't expect but will bite you if you assume they don't exist.