究竟是什么“派生Functor”做? [英] What exactly does "deriving Functor" do?
问题描述
我试图找出Haskell中派生Functor
的规则。
I已经看过有关它的留言贴,已经见过测试代码,但我似乎无法找到有关规则的官方文档。有人可以澄清和/或指向我正确的地方吗? 使用派生Functor
您必须启用 DeriveFunctor
语言杂注并将其应用于具有协变最终类型变量的多态类型---换句话说,承认一个有效的 Functor
实例。然后它会派生出显而易见的 Functor
实例。
过去一直存在一些担忧,实例并不像手写代码那样有效,尽管我似乎无法找到那些内容。
算法本身就我所能找到的 2007年由Twan Van Laarhoven首次提出,并大量使用通用的Haskell编程。
I'm trying to figure out what exactly are the rules for deriving Functor
in Haskell.
I've seen message postings about it, and I've seen test code about it, but I can't seem to find official documentation about what the rules are. Can someone please clarify and/or point me to the right place?
To use deriving Functor
you must enable the DeriveFunctor
language pragma and apply it to a polymorphic type which has a covariant final type variable---in other words, a type which admits a valid Functor
instance. It'll then derive the "obvious" Functor
instance.
There's been some concern in the past that the derived instance is not as efficient as a hand coded one is, though I cannot seem to find that material.
The algorithm itself was, as far as I could find, first proposed by Twan Van Laarhoven in 2007 and makes heavy use of Generic Haskell programming.
这篇关于究竟是什么“派生Functor”做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!