Functional programming in C++, Python, etc.

Let’s say I want to print to the screen. In pure functional programming languages like Haskell or Elm, you can simply leave it to the runtime engine to do it for you. Your function doesn’t need to do the dirty job.

If I move on to non-functional programming languages like python, C++, etc, I cannot signal the runtime environment to print text on screen, generate a random number, talk to the DB, etc. I have to do the operations myself. This makes functions impure since they are changing the state and/or relying on external states to work.

How can I write pure functions in python, C++, JS, etc since these languages lack features like Action, Command, etc to let the function communicate with the runtime environment?

I prefer learning with simple examples. If possible, can you show me how to write a pure function which prints text on the screen using a non-functional language (preferably python or C++)?

原文链接:Functional programming in C++, Python, etc.

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容