4 ms·
The shell is where you put all your side effects. Things like user input or writing to files. That way you can use pure functions on the inside. Pure functions
by xupybd 3y ago
The shell is where you put all your side effects. Things like user input or writing to files.
That way you can use pure functions on the inside. Pure functions don't allow for side effects.
- seanwilson 3y agoWhy does "imperative" imply "side effects" here though? Pure functional languages have ways of modelling side effects.
- xupybd 3y agoThey do but it's a bit of a square peg round hole. It's just easier not to use things like the IO monad.
- WorldMaker 3y agoIt's also fun to note that the IO monad in some perspectives is an abstraction for "functional core, imperative shell" moving as much of the imperative "order matters" computations to an outer "shell". The IO monad in some ways is the way of mathematically representing the "shell" of an application.
- sparkie 3y agoThe problem with monads is that they're a poor abstraction. Need to output: WriterMonad. Need input: ReaderMonad. Need to store something: StateMonad. Local mutation: MonadST. IO/global mutation: MonadIO. Transactions: MonadSTM. And to combine them: a stack of monad transformers. How delightful! This is why there's now more focus on algebraic effects as an alternative for keeping a functional core, imperative shell. Monads/transformers are just an ugly solution that even hardcore functional programmers don't want to use.
- epgui 3y agoSounds more like an unfamiliar peg than an inappropriate one, IMO.
- xupybd 3y agoYes, that may well be the case.
- turboponyy 3y agoPure functions can't perform side effects, but they can describe them. For a functional shell, your program's entry point would be composed of pure functions describing effectful actions to take. The necessary computations get bubbled up to the entry point during evaluation, at which point the runtime / compiled program executes them. (At least, this is the abstracted perspective you should view the purely functional source code from. The final program itself in practice is, of course, effectful throughout).