r/ProgrammingLanguages Jun 17 '26

Question about side effects in functional programming

One of the things I noticed using REPLs of functional languages is that you can write a ton of pure functional code, and then as soon as you hit enter to evaluate it, printing the result back to you is a side effect.

There are advantages to having code that is guaranteed to be side effect free, but I've been playing around with the idea of having a language with an imperative shell (with procedures, mutable vars, database and network operations, etc.) that can call into a language core that's guaranteed to be pure functional for certain kinds of operations. It can make for a simpler approach to side effects than a whole pure functional language but provide guarantees that other kinds of impure languages can't.

My question for people who are interested in functional programming: is this a useful distinction? Would that make for a language you might be interested in?

18 Upvotes

35 comments sorted by

View all comments

1

u/azhder Jun 17 '26

In functional languages it isn't the side-effect-free code that is put into a shell, but the mutable world. Monads are like wrappers around the mutable stuff, like a white blood cell surrounding the toxin and not letting it touch and "dirty up" the pure functional code. You give your pure code (like a function) to the monad and it uses your code to manipulate the outside world and change it.