问题:
I've come across the term 'Functor' a few times while reading various articles on functional programming, but the authors typically assume the reader already understands the term. 在阅读有关函数式编程的各种文章时,我偶然遇到过“Functor”这个术语,但作者通常认为读者已经理解了这个术语。 Looking around on the web has provided either excessively technical descriptions (see the Wikipedia article ) or incredibly vague descriptions (see the section on Functors at this ocaml-tutorial website ). 在网上浏览提供了过多的技术描述(参见维基百科文章 )或令人难以置信的模糊描述(请参阅本ocaml教程网站上的Functors部分)。
Can someone kindly define the term, explain its use, and perhaps provide an example of how Functors are created and used? 有人可以友好地定义术语,解释它的用法,并提供一个如何创建和使用Functors的例子吗?
Edit : While I am interested in the theory behind the term, I am less interested in the theory than I am in the implementation and practical use of the concept. 编辑 :虽然我对这个术语背后的理论感兴趣,但我对这个理论的兴趣不如我在实现和实际使用这个概念。
Edit 2 : Looks like there is some cross-terminoligy going on: I'm specifically referring to the Functors of functional programming, not the function objects of C++. 编辑2 :看起来有一些交叉的术语:我特别指的是函数式编程的函数,而不是C ++的函数对象。
解决方案:
参考一: https://stackoom.com/question/8WJr参考二: In Functional Programming, what is a functor?