r/functionalprogramming • • Sep 21 '24

Question Ways to be a functional language

Every functional language needs two things, a functional part, and an escape hatch where it does stuff.

The functional parts are not all identical, but they are variations on the theme of "how can we express a pure expression?" It's syntax.

But then there's the escape hatch. Haskell has monads. Original Haskell defined a program as a lazy function from a stream of input to a stream of output and I would still like to know what was wrong with that. The Functional Core/Imperative Shell paradigm says you can be as impure as you like so long as you know where you stop. Lisp says "fuck it" 'cos it's not really a functional language. Etc.

Can people fill in the "etc" for me? What are the other ways to deal with state when you're functional?

21 Upvotes

17 comments sorted by

View all comments

Show parent comment

5

u/[deleted] Sep 23 '24

Monads are not an escape hatch, I'm not sure where that idea comes from. They are pure functional code, like everything else. Maybe the IO monad causes you trouble because it can alter the real world, or have different behavior based on different user inputs.

But that comes from a misconception of the IO monad. Something of type IO A, is a function that takes the entire state of the world as an input, and outputs something of type A, along with a new state of the world. Then all apparent breaks in referential transparency and "pure functionality" can really be seen as caused by differences in the input, namely in the state of the world.

Also, its a bit silly of you to say Agda isn’t a proper grown-up language. First, people use Agda to great effect without needing input and output. They are just using it for a different purpose than altering the outside world. I don't know why you get to look down on these uses and deem them "not for grown-ups". Second, Agda does allow for input and output...