r/functionalprogramming • u/_lazyLambda • Dec 03 '25
Question Control Flow Graphs
For context I am trying to write more about why functional programming is so awesome and as i am a very visual person I become interested in diagramming out the possible behaviors of my code.
I have learned today that this is formally called a control flow graph, and that they are important to understanding and building compilers which makes sense seeing as my input to Ghc for instance is just a control flow graph, with types.
It feels like such an important idea however theres so little online discussion about control flow diagrams and how to write great programs. Is there maybe a better name for this that is analogous? Or why is this not talked about in every intro to programming or even intro to FP?
My apologies if this is too vague a question. I will edit my question if I understand it better with time.
3
u/garethrowlands Dec 04 '25
In Haskell, most of the time you want to think about simplifying (evaluating) expressions rather than control flow. That’s quite liberating.
Then think about control flow when it comes to executing effects such as, say, writing to the database. That’s more focused.
3
u/Alian713 Dec 03 '25
CFGs are useful for reasoning about optimization and most importantly for constructing static single assignment in compilers. They don't really offer much to the programmer itself in a high level language, outside of maybe explaining the code to someone else, because practically a CFG would blow up pretty quickly and the visual loses its usefulness at that point
6
u/samd_408 Dec 03 '25
I have come across CFGs only in the academic setting, programmers don’t really use them to reason about programs at least the people I have met don’t do so.
So in functional programming for me the substitution model of evaluation was eye opening, since there is no mutations and various branches in functional programming reasoning about code becomes much simpler with substitution and referential transparency.
This model is based out of lambda calculus and reductions that are defined in it, I am not much into the math side of things, maybe you can look into lambda calculus