3 ms·
Not 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.
by johnpattiyson 14y ago
Not 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.