开发者

Using mental images in functional programming

开发者 https://www.devze.com 2023-02-05 13:13 出处:网络
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 discussio

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:

Using mental images in functional programming

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号