3 ms·
> Purely functional programming doesn't work, but if you mix in a small amount of imperative code then it does. That isn't controversial nor is it an opinion.
by walrus 14y ago
> Purely functional programming doesn't work, but if you mix in a small amount of imperative code then it does.
That isn't controversial nor is it an opinion. It's just the truth. Purely functional code has no side effects. The entire point of a program is to have side effects.
- johnpattiyson 14y agoNot true. For example, a compiler can be a pure function. It accepts input that is the source code, and outputs the machine code. There's no side effect there. I admit it needs minor scaffolding to always read all of stdin first, and write all to stdout at the end, but the programme, as written by the programmer, is a pure function. This is one of several ways that Haskell worked before there was an IO monad [1], all allowing pure functional useful programmes. [1] S. Peyton Jones. Tackling the awkward squad: monadic input/output, concurrency, exceptions, and foreign-language calls in haskell. Technical report, Microsoft Research, Cambridge, 2010.
- pufuwozu 14y agoThis is even the case after the introduction of the IO monad. Monads allow referentially transparent IO. My purely functional programs actually do things! Amazing that my ivory tower allows me to say "Hello World".
- walrus 14y agoYes, the 'minor scaffolding' has side effects. That's why I said it wasn't controversial.
- qu4z-2 14y agoThe side effects in the scaffolding are purely an implementation detail. For non-interactive use (like a compiler) you could implement the program as a function taking and returning a string.
- walrus 14y agoHow would I invoke a compiler that isn't interactive? The act of invoking it is the interactivity.
- Tycho 14y agoI prefer to mix in a small amount (well, as much as I can before it starts to feel forced) if FP into my imperative programs.