問題:
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?