I've noticed the word "moral" keeps coming up in functional programming contexts. A couple examples:
Fast and Loose Reasoning is Morally Correct
Purescript Aff
documentation:
This is moral equivalent of
ErrorT (ContT Unit (Eff e)) a
.
I'm unfamiliar with these usages of the word. I can mostly infer what they're trying to say, but can we clarify more precisely what it means?
(Cross-posted on English Language & Usage)
In programming languages, a closure, also lexical closure or function closure, is a technique for implementing lexically scoped name binding in a language with first-class functions. Operationally, a closure is a record storing a function together with an environment.
Closure is a feature in JavaScript where a function has access to its own scope variables, access to the outer function variables and access to the global variables. Closure has access to its outer function scope even after the outer function has returned.
An object, at its simplest, is just a collection of state and functions that operate on that state. A closure is also a collection of state and a function that operates on that state.
Functional programming (also called FP) is a way of thinking about software construction by creating pure functions. It avoid concepts of shared state, mutable data observed in Object Oriented Programming. Functional langauges empazies on expressions and declarations rather than execution of statements.
The term "moral equivalence" in (formalized) logics, and by extension, in programming has nothing to do with appeal to morality (as in, ethical or philosophical questions). It is co-opting the term "morally", but means something different. It is generally supposed to mean "P holds, but only under certain side-conditions". These conditions are often omitted if they have no educational value, are trivial, technical and/or boring. Hence, the linked article about "moral equivalence" has nothing to do it – there are no value judgements involved here.
I don't know much about Purescript, but the way I'd interpret the statement you mentioned as "you can achieve the same thing with Aff
as ErrorT (ContT Unit (Eff e)) a
."
To give another example: Let's say you have two functions and you are only interested in a specific (maybe large) subset of their domains. Let's also say that these two functions agree on these domains, that is, for all x ∈ dom, f(x) = g(x). But for the sake of the example, maybe they do something different on 0, but you will not ever pass 0 into them (because 0 violates some assumption). One could reasonably say that f and g "are morally equivalent".
Especially in the logics community, there are other uses of "moral", for example in the phrase "the proof is morally questionable", which means that the author considers the proof to be sloppy and that it may have gaps, but technically fixable. In a particular case, namely carrying out proofs about potentially non-terminating programs, the paper you have mentioned gives such a justification, which is echoed in the title "Fast and Loose Reasoning is Morally Correct."
As Conor McBride points out on twitter, this usage stems from the category theory community, which inspires much in fp.
https://twitter.com/pigworker/status/739971825128607744
Eugenia Cheng has a good paper describing the concept of morality as used in mathematics.
http://www.cheng.staff.shef.ac.uk/morality/morality.pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With