Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using mental images in functional programming

When using a pure functional language, can some form of mental imagery or diagrams help visualise recursion and develop continuations?

like image 356
user32585 Avatar asked Jan 28 '26 03:01

user32585


1 Answers

First of all, take a look at this related discussion.

As stated there, functional programming is already quite close to mathematical notation and can be well understood and manipulated by symbolic maths. Diagrams in the OO sense are often not needed as they may model state interactions that simply don't exist in FP.

Recursion for example is very well handled in this symbolic approach. You can directly expand definitions as true equations in the mathematical sense to prove characteristics and get a quite direct, almost pseudocode-like overview.

map f [] = []
map f (x:xs) = (f x) : map f xs

Nothing clearer than that!

Nontheless, there are some metaphors that are useful for certain concepts like the functional means of modelling state / sequence, i.e. monads, applicatives, arrows. There are lots of nice images to visualize how they propagate their results. For example: The conveyer belt metaphor for arrows:

alt text

like image 96
Dario Avatar answered Jan 31 '26 09:01

Dario