What exactly does “deriving Functor” do?

前端 未结 2 1634
再見小時候
再見小時候 2021-01-01 11:05

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 abo

2条回答
  •  渐次进展
    2021-01-01 11:15

    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.

提交回复
热议问题