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?
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:
精彩评论