r/functionalprogramming • u/Inconstant_Moo • 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?
View all comments
Show parent comment
2
u/catbrane Sep 21 '24
Monads are usually (not always) implemented with continuations, so you could also think of them as prettified continuation library.
And in turn, continuations are used to implement imperative languages in denotational semantics, so you could also think of monads as a tiny imperative language you can use for the top levels of your functional program.
Of course at the same time it's all just Haskell, which anyone could write, so it's still pure, lazy, functional and easy to reason about.